我正在使用以下代码创建 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);
}
和以下方法来检查 FTP 会话是否良好 -
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;
}
有没有其他方法来验证 FTP 会话而不是编写一个愚蠢的方法?
谢谢