|
View:
New views
4 Messages
—
Rating Filter:
Alert me
|
|
|
Ftplet file uploadHey Guys,
I'm looking at using a Ftplet to intercept file uploads and write them to another location. I have tried overriding public FtpletEnum onUploadStart(FtpSession ftpSession, FtpRequest ftpRequest) throws FtpException, IOException with: public FtpletEnum onUploadStart(FtpSession ftpSession, FtpRequest ftpRequest) throws FtpException, IOException { File temp = File.createTempFile("upload", "ftp"); OutputStream stream = new FileOutputStream(File.createTempFile("upload", "ftp")); try { //tell the client 150 so he sends the file DataConnection dataConnection = ftpSession.getDataConnection().openConnection(); dataConnection.transferFromClient(stream); stream.flush(); stream.close(); ftpSession.getDataConnection().closeDataConnection(); } catch(Exception e) { logger.error("Could not upload file", e); } return FtpletEnum.RET_SKIP; } The file does not transfer. This is probably because I never sent a "150: File status okay; about to open data connection." To the client. I can not seem to figure out how to send that. The FAQ on the site explains how to send files from the database but the signature of the interface differs from what I see in SVN. Any thoughts/Comments on how I can do this would be appreciated! Thanks, Brooks Lyrette |
|
|
Re: Ftplet file uploadOn Tue, Sep 9, 2008 at 4:59 PM, Brooks Lyrette <brooks.lyrette@...> wrote:
> The file does not transfer. This is probably because I never sent a "150: > File status okay; about to open data connection." To the client. I can not > seem to figure out how to send that. The FAQ on the site explains how to > send files from the database but the signature of the interface differs from > what I see in SVN. We should really do an example of this on the web site... Besides that, and without Eclipse available at the moment to test this code, you should be able to do: session.write(new DefaultFtpReply(150, "File status okay; about to open data connection.")); /niklas |
|
|
Re: Ftplet file uploadThanks Niklas,
I somehow had overlooked using session.write(). I have it working and and here is the example for the site (Using todays M3 release): public FtpletResult onUploadStart(FtpSession ftpSession, FtpRequest ftpRequest) throws FtpException, IOException { File temp = File.createTempFile("upload", "ftp"); OutputStream stream = new FileOutputStream(temp); try { ftpSession.write(new DefaultFtpReply(150, "File status okay; about to open data connection.")); DataConnection dataConnection = ftpSession.getDataConnection().openConnection(); dataConnection.transferFromClient(stream); stream.flush(); stream.close(); ftpSession.getDataConnection().closeDataConnection(); ftpSession.write(new DefaultFtpReply(226, "Closing data connection. Requested file action successful")); } catch(Exception e) { logger.error("Could not upload file", e); } return FtpletResult.SKIP; } Cheers, Brooks On 9-Sep-08, at 11:28 AM, Niklas Gustavsson wrote: > On Tue, Sep 9, 2008 at 4:59 PM, Brooks Lyrette <brooks.lyrette@... > > wrote: >> The file does not transfer. This is probably because I never sent a >> "150: >> File status okay; about to open data connection." To the client. I >> can not >> seem to figure out how to send that. The FAQ on the site explains >> how to >> send files from the database but the signature of the interface >> differs from >> what I see in SVN. > > We should really do an example of this on the web site... > > Besides that, and without Eclipse available at the moment to test this > code, you should be able to do: > session.write(new DefaultFtpReply(150, "File status okay; about to > open data connection.")); > > /niklas |
|
|
Re: Ftplet file uploadOn Tue, Sep 9, 2008 at 5:53 PM, Brooks Lyrette <brooks.lyrette@...> wrote:
> I somehow had overlooked using session.write(). I have it working and and > here is the example for the site (Using todays M3 release): Thanks,I'll add that as an example on the site. /niklas |
| Free Forum Powered by Nabble | Forum Help |