3

我们希望能够在创建通道后更改通道上的 FTP 目录。在我们的特定用例中,FTP put 的子目录是在运行时确定的。例如:我们有用户上传的每日报告。它应该存储在 ftp 服务器中的每日文件夹中。例如:test/reports/27-11-2012/abc.pdftest/reports/28-11-2012/abc.pdf

像这样

<int-ftp:outbound-channel-adapter id="ftpOutbound" channel="ftpChannel" remote-directory="remoteDirectoryPath" 
   session-factory="ftpClientFactory" />

remoteDirectoryPath - 它应该附加运行时

请问有人可以给我们解决方案吗?

4

2 回答 2

1

利用remote-directory-expression

@beanName.method() 当前在此表达式中不可用;您将需要使用 SpEL 来生成目录...

"'test' + T(java.io.File).separator + new java.text.SimpleDateFormat('yyyyMMDD').format(new java.util.Date())"
于 2012-11-27T13:31:24.443 回答
1

您可以在运行时将目录/路径分配给 ftp:outbound-channel-adapter。我在这里处理数据。你可以看看这个。这对我有用。

xml端:

<int-ftp:outbound-channel-adapter id="ftpOutboundAdapter" session-factory="ftpSessionFactory"
    channel="sftpOutboundChannel"
    remote-directory-expression="@targetDir.get()"
    remote-filename-generator="fileNameGenerator"/>

<bean id="targetDir" class="java.util.concurrent.atomic.AtomicReference">
    <constructor-arg value="D:\PATH\"/>
</bean>

在此块中...remote-directory-expression="@targetDir.get()" 用于在运行时设置目录/路径。

Java端:

AtomicReference<String> targetDir = (AtomicReference<String>)appContext.getBean("targetDir", AtomicReference.class);
    targetDir.set("E:\PATH\");

通过,你可以设置你的路径。

于 2015-12-10T13:10:20.323 回答