2013-04-17 175 views
0

我正在使用Spring集成從FTP服務器下載/上載文件。從FTP服務器下載動態更改目錄的文件

如何在Spring FTP中動態更改remote-directory="/directory Name":入站通道。

我的客戶將基本上每天創建一個文件夾,格式爲"MM-dd-yy",並將所有文件複製到那裏。 在「FTP:入站通道」中,我沒有找到任何方式來配置此模式。我基本上有 硬編碼配置中的目錄或文件名。 我想要的是以編程方式設置路徑。因爲有時候我需要從一個direcotory下載所有文件 或者只下載一個特定的文件。

我發現"remote-directory-expression="'directory'+'/'+ new java.text.SimpleDateFormat('dd-MM-yyyy').format(new java.util.Date())"可以在FTP設置:出站通道 有在FTP任何這樣的屬性:入站通道

我的配置是這樣的:

<bean id="ftpClientFactory" 
    class="org.springframework.integration.ftp.session.DefaultFtpSessionFactory"> 
    <property name="host" value="${host}" /> 
    <property name="port" value="${availableServerPort}" /> 
    <property name="username" value="${userid}" /> 
    <property name="password" value="${password}" /> 
</bean> 

<int-ftp:inbound-channel-adapter id="ftpInbound" 
    cache-sessions="false" channel="ftpChannel" session-factory="ftpClientFactory" 
    filename-pattern="*.txt" auto-create-local-directory="true" 
    delete-remote-files="false" remote-directory="/filedirectory" 
    local-directory="${local_directory}"> 
    <int:poller fixed-rate="1000" /> 
</int-ftp:inbound-channel-adapter> 

<int:channel id="ftpChannel"> 
    <int:queue /> 
</int:channel> 

我沒有找到一個方式來做所有上述項目。

請讓我知道我該怎麼做到這一點。

回答

1

您無法使用入站適配器執行此操作,但<ftp:outbound-gateway/>可用於實現您所需的功能;描述爲here

您可以使用ls列出文件,然後使用<splitter/>和另一個使用get的網關;或者可以在表達式中使用帶有文件名模式的mget命令。

FTP sample有一個使用網關的例子

相關問題