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.