Reputation: 15557
I have the following kotlin configuration for sftp file sync with a remote server.
@Bean
fun sessionFactory(): SessionFactory<ChannelSftp.LsEntry> {
val factory = DefaultSftpSessionFactory(true)
factory.setHost(sftpHost)
factory.setPort(sftpPort.toInt())
factory.setUser(sftpUser)
factory.setPassword(sftpPasword)
factory.setAllowUnknownKeys(true)
return CachingSessionFactory<ChannelSftp.LsEntry>(factory)
}
@Bean
fun template(): SftpRemoteFileTemplate {
return SftpRemoteFileTemplate(sessionFactory())
}
@Bean
fun sftpInboundFileSynchronizer(): SftpInboundFileSynchronizer {
val fileSynchronizer = SftpInboundFileSynchronizer(sessionFactory())
fileSynchronizer.setDeleteRemoteFiles(false)
fileSynchronizer.setRemoteDirectory(sftpRemoteDirectoryDownload)
fileSynchronizer.setFilter(SftpPersistentAcceptOnceFileListFilter(PropertiesPersistingMetadataStore(), "downloaded"))
return fileSynchronizer
}
@Bean
@InboundChannelAdapter(channel = "download", poller = [Poller(cron = "0/5 * * * * *")])
fun sftpMessageSource(): MessageSource<File> {
val source = SftpInboundFileSynchronizingMessageSource(sftpInboundFileSynchronizer())
source.setLocalDirectory(File(sftpLocalDirectoryDownload))
source.setAutoCreateLocalDirectory(true)
source.setLocalFilter(FileSystemPersistentAcceptOnceFileListFilter(PropertiesPersistingMetadataStore(), "downloaded"))
return source
}
@Bean
@ServiceActivator(inputChannel = "download", outputChannel = "move")
fun resultFileHandler(): MessageHandler {
return MessageHandler { message -> publisher.handleMessage(message) }
}
@Bean
@ServiceActivator(inputChannel = "move")
fun sftpOutboundGateway(sessionFactory: SessionFactory<ChannelSftp.LsEntry>): SftpOutboundGateway {
val gateway = SftpOutboundGateway(sessionFactory, "mv", "payload")
gateway.setOutputChannelName("errorChannel")
return gateway
}
What I would like to do is move the file after it has been downloaded from the remote server; however, I have not found a way that works. Most examples are using xml configurations.
Everything is working to the resultFileHandler
method call where I can process the local file; however the MessageHandler is not getting sent to the move
channel. I am wondering what I am missing.
Upvotes: 0
Views: 870
Reputation: 174769
Consider using 3 outbound gateways instead
...LSgateway->splitter->GETgateway->process->MVgateway
The ftp sample shows a similar technique, but with RM rather than MV (although is uses XML configuration because it's quite old).
Upvotes: 1