弹簧集成 FTP 连接与 ftpoutboundGateway 命令'get'无需'ls'



我是Spring Integration的新手,我需要设置FTP连接到仅接受GETPUT命令的服务器。

我配置了实际上正在工作的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)中运行了MescagingException:

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检索文件?

如果您有这样的限制并且只能执行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
                                  });
}

最新更新