Srinath
Srinath

Reputation: 31

Spring Integration: create dynamic directories using ftp:outbound-adapter

We would like to be able to change the FTP directory on a channel, after the channel has been created. In our particular use case, the subdirectory for an FTP put is determined at runtime.for ex: we have daily reports uploaded by users.it should be store in ftp server in day wise folders. ex: test/reports/27-11-2012/abc.pdf, test/reports/28-11-2012/abc.pdf etc..

some what Like this

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

remoteDirectoryPath - it should append runtime

Please Anybody can give us solution?

Upvotes: 3

Views: 2619

Answers (2)

Kumar
Kumar

Reputation: 197

You can assign a directory/path at Runtime into ftp:outbound-channel-adapter. I am coping the data over here. You can check this out. This is working for me.

xml side:

<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>

In this block...remote-directory-expression="@targetDir.get()" is used for setting the directory/path at runtime.

Java side:

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

By, this you can set your path.

Upvotes: 1

Gary Russell
Gary Russell

Reputation: 174554

Use remote-directory-expression

@beanName.method() is currently not available in this expression; you will need to use SpEL for the directory generation...

"'test' + T(java.io.File).separator + new java.text.SimpleDateFormat('yyyyMMDD').format(new java.util.Date())"

Upvotes: 1

Related Questions