首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何配置spring-integration-sftp在文件下载到本地文件系统后移动远程文件?

如何配置spring-integration-sftp在文件下载到本地文件系统后移动远程文件?
EN

Stack Overflow用户
提问于 2018-12-12 11:08:57
回答 1查看 534关注 0票数 0

我有以下与远程服务器同步sftp文件的kotlin配置。

代码语言:javascript
复制
@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通道。我想知道我错过了什么。

EN

回答 1

Stack Overflow用户

发布于 2018-12-12 22:41:23

考虑使用3个出站网关

代码语言:javascript
复制
...LSgateway->splitter->GETgateway->process->MVgateway

ftp sample展示了类似技术,但使用的是RM而不是MV (尽管is使用XML配置,因为它非常旧)。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/53735484

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档