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 massimiliano basilica <ma...@yahoo.it> on 2009/05/13 16:27:44 UTC
(custom Ftplet) onConnect method problem
Hi I need some hint on using the FTPServer 1.0.
I need to grant the access to the FTPServer to a list of well-known hosts, identified by their ip address.
I've defined the following ftplet overriding the onConnect method.
In this method I checked the ip address of the client, if the address is not in the granted list, the method returns the FtpletResult.DISCONNECT value.
Eventually, I made a test, using an host not present in the granted list, but the FTPServer gives me the access.
This is an example code:
public class CustomizedFtplet extends org.apache.ftpserver.ftplet.DefaultFtplet {
static Logger log = null;
public FtpletResult onUploadStart(FtpSession session, FtpRequest request)
throws FtpException, IOException {
System.out.println("==> Upload");
return FtpletResult.DEFAULT;
}
public FtpletResult onLogin (FtpSession session, FtpRequest request)
throws FtpException, IOException {
System.out.println("==> On Login " + session.getClientAddress());
return FtpletResult.DEFAULT;
}
/**
* this method has been overridden to intercept IP address, Port and HostName
*/
public FtpletResult onConnect(FtpSession session) throws FtpException,
IOException {
FtpletResult retVal = FtpletResult.DISCONNECT;
String ip = session.getClientAddress().getAddress().getHostAddress();
System.out.println("ApacheFtplet Client Address is "+ip);
System.out.println("ApacheFtplet Client Port is "+session.getClientAddress().getPort());
System.out.println("ApacheFtplet Client HostName is "+session.getClientAddress().getHostName());
System.out.println("FtpletResult " + retVal);
if (grentedHost(ip))
retVal = FtpletResult.DEFAULT;
return retVal;
}
private boolean grantedHost(String ip) {
return false;
}
I registered the ftplet using: Map<String,Ftplet> ftplets = new HashMap<String,Ftplet>();
ftplets.put("custom",new CustomizedFtplet());
serverFactory.setFtplets(ftplets);
Do you think I made some mistake?Is there a FTPServer life cicle I didn't take in account?
Note that the onLogin Method works fine (the session is closed when it returns FtpletResult.DISCONNECT).It seems that the FtpletResult.DISCONNECT for the method onConnect is not handled on the upper layer.
Thank you in advance for your help.
I'm looking forward your answering.
Massimiliano.
Re: (custom Ftplet) onConnect method problem
Posted by Niklas Gustavsson <ni...@protocol7.com>.
On Wed, May 13, 2009 at 5:01 PM, Sai Pullabhotla
<sa...@jmethods.com> wrote:
> This appears to be a bug in the FtpServer where it is ignoring the return
> value from the Ftplet(s). Can some one else confirm too?
Agreed. I will work on a fix tonight that will be available in 1.0.1
that I hope to put up for voting in the next few days.
/niklas
Re: (custom Ftplet) onConnect method problem
Posted by Sai Pullabhotla <sa...@jmethods.com>.
This appears to be a bug in the FtpServer where it is ignoring the return
value from the Ftplet(s). Can some one else confirm too?
Sai Pullabhotla
www.jMethods.com
On Wed, May 13, 2009 at 9:27 AM, massimiliano basilica <
massimiliano.basilica@yahoo.it> wrote:
>
> Hi I need some hint on using the FTPServer 1.0.
>
> I need to grant the access to the FTPServer to a list of well-known hosts,
> identified by their ip address.
>
> I've defined the following ftplet overriding the onConnect method.
> In this method I checked the ip address of the client, if the address is
> not in the granted list, the method returns the FtpletResult.DISCONNECT
> value.
>
> Eventually, I made a test, using an host not present in the granted list,
> but the FTPServer gives me the access.
>
> This is an example code:
>
> public class CustomizedFtplet extends
> org.apache.ftpserver.ftplet.DefaultFtplet {
> static Logger log = null;
>
> public FtpletResult onUploadStart(FtpSession session, FtpRequest
> request)
> throws FtpException, IOException {
>
> System.out.println("==> Upload");
>
> return FtpletResult.DEFAULT;
> }
> public FtpletResult onLogin (FtpSession session, FtpRequest
> request)
> throws FtpException, IOException {
>
> System.out.println("==> On Login " +
> session.getClientAddress());
>
> return FtpletResult.DEFAULT;
> }
>
> /**
> * this method has been overridden to intercept IP address, Port
> and HostName
> */
> public FtpletResult onConnect(FtpSession session) throws
> FtpException,
> IOException {
> FtpletResult retVal = FtpletResult.DISCONNECT;
>
> String ip =
> session.getClientAddress().getAddress().getHostAddress();
> System.out.println("ApacheFtplet Client Address is
> "+ip);
> System.out.println("ApacheFtplet Client Port is
> "+session.getClientAddress().getPort());
> System.out.println("ApacheFtplet Client HostName is
> "+session.getClientAddress().getHostName());
> System.out.println("FtpletResult " + retVal);
> if (grentedHost(ip))
> retVal = FtpletResult.DEFAULT;
> return retVal;
> }
>
>
> private boolean grantedHost(String ip) {
>
> return false;
> }
>
>
> I registered the ftplet using: Map<String,Ftplet> ftplets = new
> HashMap<String,Ftplet>();
> ftplets.put("custom",new CustomizedFtplet());
> serverFactory.setFtplets(ftplets);
>
> Do you think I made some mistake?Is there a FTPServer life cicle I didn't
> take in account?
> Note that the onLogin Method works fine (the session is closed when it
> returns FtpletResult.DISCONNECT).It seems that the FtpletResult.DISCONNECT
> for the method onConnect is not handled on the upper layer.
> Thank you in advance for your help.
> I'm looking forward your answering.
> Massimiliano.
>
>
>
>