2014-07-14 81 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