2014-07-14 79 views
0

我尝试从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(); 
} 

测试通过,看起来一切正常,但它没有。 你有什么想法吗? 感谢您的提前。

+0

你的意思是它不从FTP下载文件,当你的本地dir'ftp /'不为空时?尝试显示针对该糟糕情况的'org.springframework.integration'类的DEBUG日志。 –

+0

是的,那正是我的意思。我会尝试获取这些日志,然后编辑我的帖子。 – mlethys

回答

1

这是在测试用例吗?

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

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

将睡眠添加到测试结束以进行验证。

+0

我不确定我是否理解你的权利。如果在本地目录中已经存在任何其他文件,是否应该从服务器提取文件?但是,当我想要什么时,例如获取存储在ftp服务器上的所有文件,并且我不想处理它们? – mlethys

+0

好的,我添加Thread.sleep(int时间)后,一切正常。非常感谢。 – mlethys