【问题标题】:Downloading file using spring integration使用弹簧集成下载文件
【发布时间】:2014-07-14 13:33:38
【问题描述】:

当我尝试从 ftp 服务器下载文件时遇到一些问题。 当我尝试将下载的文件保存到空文件夹时,一切正常,但是当文件夹包含任何其他文件时,我的代码甚至无法连接到服务器。 这是我的上下文文件:

    <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>
    <int:channel id="getFtpChannel">
    <int:queue/>
</int:channel>
<int-ftp:inbound-channel-adapter local-directory="ftp/" 
            channel="getFtpChannel" 
            session-factory="ftpClientFactory" 
            remote-directory="./"
            auto-create-local-directory="false"
            delete-remote-files="true"
            filename-pattern="*.exi">
    <int:poller fixed-rate="10000"/>
</int-ftp:inbound-channel-adapter>

还有我的java代码:

public void receiveTest() {
    ConfigurableApplicationContext context = 
            new FileSystemXmlApplicationContext("/src/citrus/resources/citrus-context.xml");
    PollableChannel channel = context.getBean("getFtpChannel", PollableChannel.class);
    channel.receive(); 
    context.close();
}

测试通过,看起来一切正常,但事实并非如此。 你有什么想法吗? 感谢您的提前。

【问题讨论】:

  • 当您的本地目录ftp/ 不为空时,您的意思是它不会从FTP 下载文件吗?尝试为该不良情况显示org.springframework.integration 类别的调试日志。
  • 是的,这正是我的意思。我会尝试获取这些日志,然后我会编辑我的帖子。

标签: java xml ftp spring-integration


【解决方案1】:

这是在测试用例中吗?

如果已经有本地文件,我们不会从 ftp 获取,直到这些文件被处理。

几周前我们有一个类似的问题,当时用户的测试用例在到达我们查找远程文件的地步之前就退出了。

在测试结束时添加睡眠以进行验证。

【讨论】:

  • 我不确定我是否理解正确。您是否说如果本地目录中已存在任何其他文件,则不应从服务器获取文件?但是当我想要获取存储在 ftp 服务器上的所有文件并且我不想处理它们时怎么办?
  • 好的,在我添加 Thread.sleep(int time) 之后一切正常。非常感谢。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2020-07-09
  • 2018-09-11
  • 2018-04-08
  • 1970-01-01
  • 2011-08-06
  • 1970-01-01
相关资源
最近更新 更多