【问题标题】:Spring FTP Integration : How to verify FTP session?Spring FTP 集成:如何验证 FTP 会话?
【发布时间】:2016-12-28 17:14:41
【问题描述】:

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

谢谢

【问题讨论】:

    标签: spring-integration spring-integration-sftp


    【解决方案1】:

    嗯,是的,如果您已经使用 CachingSessionFactory,则不需要该方法。

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

    【讨论】:

    • 完全正确。感谢您提供此功能。但是,如果远程主机已关闭,或者我们在创建 CachingSessionFactory 时传递了错误的远程主机,应用程序不会在日志中报告任何错误,并且我们无法跟踪应用程序是否工作正常。如果 ftpSession 有任何问题,有什么方法可以在日志中获取通知或错误?请指教。
    • 好吧,由于CachingSessionFactory 以延迟加载方式工作,确实没有任何挂钩可以在启动时跟踪错误的连接选项。因此,您绝对应该在需要确定的时候提供自制机制来验证。所以,那么你的方法是不错的选择。
    猜你喜欢
    • 1970-01-01
    • 2020-04-21
    • 2013-02-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多