使用spring-integration列出ftp中的文件

米莱斯蒂

我想使用spring-integration列出FTP服务器上的所有文件,例如,在屏幕上打印它们。我已经做了这样的事情:

语境:

<int:channel id="toSplitter">
    <int:interceptors>
        <int:wire-tap channel="logger"/>
    </int:interceptors>
</int:channel>

<int:logging-channel-adapter id="logger" log-full-message="true"/>
<int:splitter id="splitter" input-channel="toSplitter" output-channel="getFtpChannel"/>

<int-ftp:outbound-gateway id="gatewayLS"
                        session-factory="ftpClientFactory"
                        request-channel="inbound"
                        command="ls"
                        expression="payload"
                        reply-channel="toSplitter"/>
<int:channel id="getFtpChannel">
    <int:queue/>
</int:channel>
    <bean id="ftpClientFactory"
        class="org.springframework.integration.ftp.session.DefaultFtpSessionFactory">
    <property name="host" value="${host}"/>
    <property name="username" value="${user}"/>
    <property name="password" value="${password}"/>
    <property name="clientMode" value="0"/>
    <property name="fileType" value="2"/>
    <property name="bufferSize" value="10000000"/>                  
</bean>

Java代码:

ConfigurableApplicationContext context = 
            new FileSystemXmlApplicationContext("/src/citrus/resources/citrus-context.xml");
final FtpFlowGateway ftpFlow = context.getBean(FtpFlowGateway.class);
ftpFlow.lsFiles("/");
PollableChannel channel = context.getBean("getFtpChannel", PollableChannel.class);
variable("tt", channel.receive().toString());
echo("${tt}");

输出:

11:09:17,169 INFO  port.LoggingReporter| Test action <echo>
11:09:17,169 INFO    actions.EchoAction| [Payload=FileInfo [isDirectory=false,  isLink=false, Size=3607, ModifiedTime=Tue Jul 15 14:18:00 CEST 2014,       Filename=Smoke03_angart30_st40.exi, RemoteDirectory=/, Permiss
ions=-rw-r--r--]][Headers= {replyChannel=org.springframework.integration.core.MessagingTemplate$TemporaryReplyChannel@7829b776, sequenceNumber=1,  errorChannel=org.springframework.integration.core.MessagingTempla
te$TemporaryReplyChannel@7829b776, file_remoteDirectory=/, sequenceSize=1, correlationId=49b57f2d-4dbf-4a89-b5b8-0dfb15bca2be, id=0a58ad65-74b4-4aae-87be- aa6034a41776, timestamp=1405501757060}]
11:09:17,169 INFO  port.LoggingReporter| Test action <echo> done
11:09:17,169 INFO  port.LoggingReporter| TEST STEP 1/1 done

输出很好,但是当我不知道FTP上存储了多少文件时,该怎么做才能打印此信息?(此代码仅打印一个文件)。我试过检查是否channel.receive()为空,但测试只是冻结。

阿尔特姆·比兰(Artem Bilan)

既然你发送的结果LS<splitter>,你getFtpChannel将收到FileInfo<?>的对象一个接一个。

要打印它们,您实际上应该有一个无限循环:

while (true) {
  variable("tt", channel.receive().toString());
  echo("${tt}");
}

要停止该应用程序,您应该提供一些内容shoutDownHook或从控制台输入中监听一些内容。

还有一点,用infinite阻止应用程序是不好的receive()没有重载方法,该方法会应用timeout参数。最后一个可能对确定循环的结束很有用:

while (true) {
  Message<?> receive = channel.receive(10000);
  if (receive == null) {
      break;
  }
  variable("tt", receive.toString());
  echo("${tt}");
}

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

使用 goftp 列出 FTP 文件

使用Spring Integration发送成功的FTP文件上传消息

通过Spring-Integration下载FTP文件?

如何使用Perl在ftp目录中列出早于20分钟的文件?

文件夹中的Spring Integration Ftp Outbound Gateway特殊字符名称

如何从Spring Integration ftp中的服务器下载以“ xyz”开头的文件名?

使用 SftpOutboundGateway 列出 spring 批处理中的远程文件

FTP/SFTP 使用 Spring Integration 发送带前缀的临时文件?

为每个Ftp文件同时运行Spring Integration流

Spring Integration中无法使RequestHandlerRetryAdvice与Ftp.outboundGateway一起使用

Docker容器中的Spring Integration FTP:不触发流

使用Spring Integration ftp支持将文件从ftp服务器传输到另一个ftp服务器

使用Spring Integration同时读取CSV文件

使用Spring Integration DSL逐行读取文件

Spring Integration Design - 处理文件中的行

在Spring Integration中检测文件更改

问题-使用-grep列出目录中的文件

列出Gnat中未使用的文件

Spring Integration:仅从FTP服务器下载新文件或更新文件?

Spring Integration DSL FTP问题

在Spring Boot中列出Templates目录中的文件

如何在nodejs中列出ftp文件?

如何使用Spring Integration在IntegrationFlow链中通过SFTP上传文件?

Spring Integration Java-如何使用@InboundChannelAdapter检查目录中的文件?

使用Spring Batch Integration为AWS S3中的每个新文件启动JobLaunchRequest

使用Spring Integration移至GCP存储后如何从本地目录中删除文件

不使用 xml 文件的 Spring Integration 中的日志记录过程

使用 Spring Integration 中的 Java 配置从 SFTP 复制和移动文件

Spring Integration-具有不同文件夹的动态multible sftp / ftp会话