I am using following code to create ftpSessionfactory -
@Bean
@Lazy(false)
public SessionFactory<FTPFile> ftpSessionFactory() {
DefaultFtpSessionFactory sf = new DefaultFtpSessionFactory();
sf.setHost(server);
sf.setPort(port);
sf.setUsername(username);
sf.setPassword(password);
return new CachingSessionFactory<FTPFile>(sf);
}
and following method to check if FTP session is good -
private boolean isFTPSessionOK() {
try {
SessionFactory<FTPFile> ftpSessionFactory = ftpSessionFactory();
boolean open = ftpSessionFactory.getSession().isOpen();
System.out.println("Session is good ? "+ open);
return open;
} catch (Exception e) {
e.printStackTrace();
}
return false;
}
Is there any other way, to verify FTP Session instead of writing a dumb method?
Thanks
Well, yes, you don't need that method if you use
CachingSessionFactory
already.Each time to perform
ftpSessionFactory.getSession()
thepool
abstraction ensures to return to you a valid, open instance.