2013-04-17 172 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有一个使用网关的例子

相关问题