【问题标题】:How to receive list of directories or file from ftp server with int-ftp:outbound-gateway?如何使用 int-ftp:outbound-gateway 从 ftp 服务器接收目录或文件列表?
【发布时间】:2015-04-19 11:15:40
【问题描述】:

我定义了 ftp 适配器来连接到 ftp 服务器,但是我看到了 ftp 服务器日志并且没有看到发送到 ftp 服务器的请求。我的适配器代码是:

<bean id="ftpClientFactory" class="org.springframework.integration.ftp.session.DefaultFtpSessionFactory">
    <property name="host" value="127.0.0.1"/>
    <property name="port" value="21"/>
    <property name="username" value="banks_reader"/>
    <property name="password" value="123456"/>
    <property name="clientMode" value="2"/>
    <property name="fileType" value="2"/>

</bean>


<int:channel id="inbound1">
    <int:queue/>
</int:channel>
<int:channel id="outbound"/>
<int-ftp:outbound-gateway id="gateway1"
                          session-factory="ftpClientFactory"
                          request-channel="inbound1"
                          reply-channel="outbound"
                          reply-timeout="777"
                          auto-create-local-directory="false"
                          auto-startup="true"
                          filename-pattern="*"
                          remote-file-separator="/"
                          command="ls"
                          command-options="-1 -f"
                          expression="payload"
                          order="1"
                          mput-regex=".*">
    <int:poller fixed-delay="1000"/>
</int-ftp:outbound-gateway>

其中显示:

DEBUG PollingConsumer:208 - Received no Message during the poll, returning 'false' in application log

更改用户名和密码进行测试时(假通行证和用户名)不更改任何内容并抛出异常

【问题讨论】:

    标签: spring ftp spring-integration outbound


    【解决方案1】:

    您的配置看起来不错,但您有点错过了方法。 &lt;int-ftp:outbound-gateway&gt; 是一个事件驱动的请求/回复组件,它不能对 FTP 做任何事情,直到 inbound1 中没有 message。 即使是&lt;queue&gt;,也只有在没有Received no Message during the poll 时,&lt;poller&gt; 才会启动它的工作。

    由于您使用expression="payload",因此您的requestMessage 必须包含来自您的FTP 用户主页的payloadremote dir

    所以,只需将这样的消息发送到inbound1,让我们知道它是怎么回事!

    更新

    要使用与payload 相同的dir 定期对&lt;int-ftp:outbound-gateway&gt; 执行LS 命令,您必须进行如下配置:

    <inbound-channel-adapter channel="inbound1" expresssion="'/'">
        <poller fixed-delay="10000"/>
    </inbound-channel-adapter>
    

    有了那个(和你的&lt;gateway&gt;)案例,就不需要把inbound1频道作为&lt;queue&gt;

    【讨论】:

    • 再向inbound1发送一次消息。你没有分享你的流程的开始,这就是为什么我无法弄清楚你有哪个问题。您不能配置假 &lt;inbound-channel-adapter&gt; 来定期启动您的流程。
    • ,没错,在应用启动中添加int:gateway并运行toFtpFlow.lsGetAndRmFiles("/");,可以,但是只执行一次,如何定期语句运行命令并获取对象列表?
    • 感谢 @Artem 帮助我并更新您的答案,根据 link 文档,我需要在我的 ftp 服务器中运行 ls,mv,... 命令,如何运行 toFtpFlow.lsGetAndRmFiles("/"); 语句和获取对象列表?
    • 您可以通过一组连续的&lt;int-ftp:outbound-gateway&gt; 组件来执行此操作:第一个用于LS,然后是&lt;splitter&gt;,再一个&lt;int-ftp:outbound-gateway&gt; 用于MV
    • 感谢@Artem,第一步我需要定期调用 LS commad 并运行&lt;int-ftp:outbound-gateway&gt; flow 到 ls mv ...,如何先定期运行&lt;int-ftp:outbound-gateway&gt; 来运行 ls 命令?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-04-08
    • 1970-01-01
    • 1970-01-01
    • 2021-01-29
    • 1970-01-01
    • 2023-03-21
    • 2013-03-20
    相关资源
    最近更新 更多