我是Spring Integration的新手,我需要设置FTP连接到仅接受GET
和PUT
命令的服务器。
我配置了实际上正在工作的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
,请考虑将FtpOutboundGateway
与MessageSessionCallback
一起使用的变体:
@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
});
}