我具有以下Kotlin配置,用于与远程服务器同步sftp文件。
@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
}
我想做的是从远程服务器下载文件后移动文件;但是,我还没有找到一种可行的方法。大多数示例都使用xml配置。
一切正常,可以处理resultFileHandler
方法调用,在这里我可以处理本地文件;但是MessageHandler没有发送到move
通道。我想知道我在想什么。
答案 0 :(得分:1)
考虑改用3个出站网关
worksheet.merge_range('A3:A10', 'Merged Range', merge_format)
worksheet.merge_range('A10:A17', 'Merged Range', merge_format)
ftp sample显示了类似的技术,但是使用RM而不是MV(尽管使用XML配置是因为它已经很老了。)