【问题标题】:Spring Integration FTP connection with FtpOutboundGateway command 'get' without 'ls'Spring Integration FTP 连接与 FtpOutboundGateway 命令 'get' 没有 'ls'
【发布时间】:2018-02-22 12:07:21
【问题描述】:

我是 Spring Integration 的新手,我需要建立一个到只接受 GETPUT 命令的服务器的 FTP 连接。

我配置了一个 FtpOutboundGateway@MessagingGateway ,这实际上是有效的。

但是FtpOutboundGateway 的设置

    @Bean
    @ServiceActivator(inputChannel = "ftpFetchFile")
    public MessageHandler getFile() {
    FtpOutboundGateway gateway = new FtpOutboundGateway(this.ftpSessionFactory(), "get", "payload");
        gateway.setLocalDirectoryExpression(EXPRESSION_PARSER.parseExpression("#remoteDirectory")); 
        gateway.setFileExistsMode(FileExistsMode.REPLACE);
        return gateway;
    }

还在GET 之前执行LS 命令。这实际上是一种很好的方法,可以证明文件存在,但是由于服务器正在动态创建文件,LS 永远不会返回任何现有文件,因此在来自org.springframework.integration.file.remote.gateway.AbstractRemoteFileOutboundGateway.get(Message<?>, Session<F>, String, String, String, boolean) 的 MessagingException 中运行:

failure occurred in gateway sendAndReceive: Dispatcher failed to deliver Message; nested exception is org.springframework.messaging.MessagingException: someFile.txt is not a file

有没有办法用 Ftp GET 检索文件?

【问题讨论】:

    标签: ftp spring-integration


    【解决方案1】:

    如果您有这样的限制并且只能执行GET,请考虑使用FtpOutboundGatewayMessageSessionCallback 的变体:

    @Bean
    @ServiceActivator(inputChannel = "ftpFetchFile")
    public MessageHandler getFile() {
        return new FtpOutboundGateway(this.ftpSessionFactory(), 
                         (session, requestMessage) -> {
    
                // Call Session.read() or Session.readRaw() and return the result of reading
    
                                      });
    }
    

    【讨论】:

    • 或者在服务激活器中使用FtpRemoteFileTemplate
    • 感谢您的回答,我会看看这个
    猜你喜欢
    • 2014-11-04
    • 2016-06-17
    • 1970-01-01
    • 2021-07-28
    • 1970-01-01
    • 2015-09-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多