Actually I noted after replying that what we really do is this:
   client uploads  "myfile.txt"
   onUploadstart receives myfile.txt  and does some security checks
   onUploadEnd renames myfile.txt to PREFIX_myfile.txt and moves it to
destination folder ( For this you have to get the FtpFileObject
session.getFileSystemView().getFile(request.getArgument())   and cast
it to NativeFtpFile so you can  access the physicalFile - In trunk
this cast is probably no longer needed )

Our app only processes files starting with "PREFIX" and will remove
that part of the filename.

If you definitely have to change the filename  before upload you
should implement your own STOR command or provide your own filesystem
implementation. Im guessing you probably want to avoid concurrency
problems and thus you change the filename to .swp until upload has
finished. A custom filesystem  would be a good solution to handle this
- maybe even you could donate that code for I guess is a pretty common
request.




2009/5/12 massimiliano basilica <[email protected]>:
> Thank you very much for your fast reply.
> For my purpose  the good solution is to use onUploadStart() ftpLet method for 
> the first rename and onUploadEnd for the final one.
> I tried to use the following method
>        public FtpletResult onUploadStart(FtpSession session, FtpRequest 
> request)       throws FtpException, IOException {
>                System.out.println("==> Upload");
>                return FtpletResult.DEFAULT;    }
>
> I guessed I was been able to change the input file name using the FtpRequest 
> request, but this class/Interface provide only get method 
> (i.e. request.getArgument();)
> How can I change the input file name? Is there another way to do it?I have 
> the same problem for the method onUploadEnd.Please, Could you send me an 
> example?
>
>
> Thank you in advance for your useful help.
> Massimiliano.
>
> --- Mar 12/5/09, David Latorre <[email protected]> ha scritto:
>
> Da: David Latorre <[email protected]>
> Oggetto: Re: STOR a temporary file
> A: [email protected]
> Data: Martedì 12 maggio 2009, 11:42
>
> 2009/5/12 massimiliano basilica <[email protected]>:
>> HI all,
>> I'm using FTPServer 1.0.I need that the FTPServer stores a file with a 
>> temporary file extention and  rename it with originally file name.The 
>> scenario is:The Client sends the file "FirstFile.txt" (put 
>> FirstFile.txt).The FTPServer must store it as FirstFile.txt.tmp. When the 
>> uploading is completed, the FTPServer must rename it as FirstFile.txt.All 
>> must be transparent to the Client, it can't use the command
>
> Hello massimiliano,
>
> I have implemented something like that and it's kinda working but see
> several potential problems:
>
>  - There's no way to know (at the server side) if the file has been
> transferred correctly. When the data connection is closed, the server
> thinks the file transfer finished correctly but this must not be the
> case. Thus, the file could be renamed to it's final name even though
> the connection was aborted -> you end up with an uncomplete file.
>
>  - Currently the onUploadEnd ftplet method will be executed after the
> response to the client is sent. So if the file-rename fails the client
> wouldn't know that anything happened. If this is a problem for you
> (most likely) you should use your own STOR method. Otherwise, you can
> use onUploadStart() ftpLet method for the first rename and onUploadEnd
> for the final one.
>
> Since we had this implemented before the change in ftpets what I did
> is to provide my own STOR method which is an exact copy of Ftpserver's
> implementation but adding a call to  the "rename-to-.txt" method  in
> the Ftplet before the response is written to the session.
>
>
>
>
>>
>>
>>
>>
>>
>>
>>
>
>
>
>

Reply via email to