簡體   English   中英

從各個子目錄遞歸地從FTP服務器下載文件

[英]Downloading files from FTP server recursively from various sub directories

我已經使用帶有出站網關的入站通道適配器在XML文件中配置了bean。 我在java類中使用@serviceactivator來調用通道,但是僅獲取根文件夾中的文件無法從子目錄中獲取文件。

我的XML文件:

<int:inbound-channel-adapter channel="inbound1" expression="'/'">
 <int:poller fixed-delay="3000"/>
</int:inbound-channel-adapter>

<int-ftp:outbound-gateway id="gatewayGet"
        session-factory="ftpClientFactory"
        request-channel="inbound1"
        local-directory="C:/Users/pprakash/Desktop/DataFiles/actual"
        auto-startup="true"
        command="mget"
        command-options="-R"
        filename-pattern="*.csv"
        expression="'actual/*/*'"
        reply-channel="outbound"/>

<int:channel id="outbound">
<int:interceptors>
    <int:wire-tap channel="logger"/>
</int:interceptors>
</int:channel>
<int:logging-channel-adapter id="logger" log-full-message="true" />

'<bean id="ftpClientFactory"
                  class="org.springframework.integration.ftp.session.DefaultFtpSessionFactory">
            <property name="host" value="192.168.79.1"/>
            <property name="port" value="21"/>
            <property name="username" value="*****"/>
            <property name="password" value="*****"/>
            <property name="bufferSize" value="100000"/>
</bean>'

我的Java代碼就像:-

 static int index=0;
@ServiceActivator(inputChannel = "inbound1")
public void foo1(File file) throws InterruptedException {
     logger.debug("Inbound msg to  gateway :[ "+(index++)+"]" +    file.getAbsolutePath());
}

@ServiceActivator(inputChannel = "outbound")
public void foo2(List<File> file) throws InterruptedException {
    System.out.println("outbound gateway");
   logger.debug("File Received  :[ "+(index++)+"]" + file.size());

}

filename-pattern="*.csv"

除非您的子目錄也符合該模式,否則不會對其進行掃描。

請參閱說明文件

例如, filename-regex="(subDir|.*1.txt)"將在遠程目錄和子目錄subDir檢索所有以1.txt結尾的文件。 如果過濾了子目錄,則不會對該子目錄進行其他遍歷。

(我的重點)。

因此,您的模式必須使樹中的子目錄能夠被遍歷。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM