Reputation: 359
I have implemented SFTP upload to a remote server using the example here.
My requirement is that I will have to upload the same file to multiple directories on the same server. The exact number or location of the directories will be known post-production.
Currently, my implementation allows for upload to a single directory on a single server, by setting remoteDirectoryExpression
on the message handler. The remoteDirectoryExpression
comes from a property file. It is expected that the remaining directories will be configured in a comma-separated way on the same property. I would like my implementation to extract each of the these comma-separated directories from the property and upload the file to each of them.
Is this even possible? I came across publish-subscribe channels but am currently struggling to understand how to include them in my implementation. Even then, pub-sub channels seem to require pre-configuring in the code where one channel = one directory. So am I even on the right track?
Upvotes: 2
Views: 1495
Reputation: 45
try with publishSubscribeChannel
.publishSubscribeChannel(s -> s
.subscribe(f -> f
.handle(Sftp.outboundAdapter(sftpSessionFactory())
.remoteDirectory(getRemoteRootDir() + remoteDirectory1)
.temporaryFileSuffix(".tmp")))
.subscribe(f -> f
.handle(Sftp.outboundAdapter(sftpSessionFactory())
.remoteDirectory(getRemoteRootDir() + remoteDirectory2)
.fileNameExpression(fileRenameExpression)
.temporaryFileSuffix(".tmp")))
Upvotes: 1
Reputation: 174504
There is nothing built-in to do that.
The simplest way would be to create a custom splitter upstream and emit n messages with the directory in a header and then use the header value in the remote directory expression.
Upvotes: 2