You are viewing a plain text version of this content. The canonical link for it is here.
Posted to ftpserver-users@mina.apache.org by Brooks Lyrette <br...@gmail.com> on 2008/09/09 16:59:54 UTC
Ftplet file upload
Hey 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 upload
Posted by Niklas Gustavsson <ni...@protocol7.com>.
On Tue, Sep 9, 2008 at 5:53 PM, Brooks Lyrette <br...@gmail.com> 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
Re: Ftplet file upload
Posted by Brooks Lyrette <br...@gmail.com>.
Thanks 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@gmail.com
> > 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 upload
Posted by Niklas Gustavsson <ni...@protocol7.com>.
On Tue, Sep 9, 2008 at 4:59 PM, Brooks Lyrette <br...@gmail.com> 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