1

我正在使用以下代码创建 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 会话而不是编写一个愚蠢的方法?

谢谢

4

1 回答 1

1

好吧,是的,如果您已经使用过,则不需要该方法CachingSessionFactory

每次执行ftpSessionFactory.getSession()抽象pool确保返回给您一个有效的、开放的实例。

于 2016-12-28T17:42:13.850 回答