2
votes

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?

2
This seems like a very inefficient way to do things. Can you not just upload it once and then copy it locally to every directory?RaminS
@Gedarme Yes! That makes sense. Let me give that a try.user1825770
That would also save you a lot of bandwidth if the files are large.RaminS
@Gendarme Apparently it is not supported :) stackoverflow.com/questions/37664612/…user1825770

2 Answers

2
votes

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.

1
votes

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