从各个子目录递归地从 FTP 服务器下载文件

Downloading files from FTP server recursively from various sub directories

我在 XML 文件中配置了 beans,其中的入站通道适配器带有出站网关。我在 java class 中使用 @serviceactivator 来调用 channel.But m 获取根文件夹中的文件,但无法从子目录中获取文件。

我的 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"

除非您的子目录也匹配该模式,否则它们将不会被扫描。

the documentation

For example, filename-regex="(subDir|.*1.txt)" will retrieve all files ending with 1.txt in the remote directory and the subdirectory subDir. If a subdirectory is filtered, no additional traversal of that subdirectory is performed.

(我的重点)。

因此,您的模式需要遍历树中的子目录。