Spring集成FTP连接与FtpOutboundGateway命令'get'没有'ls'

时间:2018-02-22 12:07:22

标签: ftp spring-integration

我是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;
    }

也会在LS之前执行GET命令。这实际上是一种很好的方式,证明文件存在,但是当服务器正在动态创建文件时,LS永远不会返回任何现有文件,因此在{{1}的MessagingException中运行}:

org.springframework.integration.file.remote.gateway.AbstractRemoteFileOutboundGateway.get(Message<?>, Session<F>, String, String, String, boolean)

有没有办法检索只有Ftp failure occurred in gateway sendAndReceive: Dispatcher failed to deliver Message; nested exception is org.springframework.messaging.MessagingException: someFile.txt is not a file 的文件?

1 个答案:

答案 0 :(得分:0)

如果您有此类限制且只能执行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 }); }

Reader in = new FileReader("path/to/file.csv");
Iterable<CSVRecord> records = CSVFormat.EXCEL.parse(in);
for (CSVRecord record : records) {
String lastName = record.get("Last Name");
String firstName = record.get("First Name");
}