gpt4 book ai didi

java - Spring 集成: downloading only new or updated files from FTP server?

转载 作者:行者123 更新时间:2023-11-30 06:13:57 25 4
gpt4 key购买 nike

我正在使用 Spring Integration 编写 FTP 客户端,用于从远程 FTP 服务器获取文件。此服务必须下载很大的文件,因此多次下载同一文件并不是最佳选择。

这是我的配置:

@Bean
open fun ftpSessionFactory() = DefaultFtpSessionFactory().apply {
setHost(env.getProperty(FTP_HOST))
setPort(env.getProperty(FTP_PORT)!!.toInt())
setUsername(env.getProperty(FTP_USER))
setPassword(env.getProperty(FTP_PASSWORD))
}

@Bean
open fun ftpInboundFileSynchronizer() = FtpInboundFileSynchronizer(
ftpSessionFactory()).apply {
setDeleteRemoteFiles(false)
setRemoteDirectory(env.getProperty(FTP_REMOTE_DIRECTORY))
setFilter(FtpSimplePatternFileListFilter(env.getProperty(FTP_FILTER)))
}

@Bean
@InboundChannelAdapter(channel = "ftpChannel")
open fun ftpMessageSource() = FtpInboundFileSynchronizingMessageSource(
ftpInboundFileSynchronizer()).apply {
setLocalDirectory(File(env.getProperty(FTP_LOCAL_DIRECTORY)))
setAutoCreateLocalDirectory(true)
setLocalFilter(AcceptOnceFileListFilter<File>())
maxFetchSize = 1
}

@Bean(name = [(PollerMetadata.DEFAULT_POLLER)])
open fun defaultPoller() = PollerMetadata().apply {
maxMessagesPerPoll = 1
}

我是否下载与 FTP_FILTER 匹配的所有文件或刚刚更改的文件?

最佳答案

除了 FtpSimplePatternFileListFilter 之外,您还需要对远程部分使用 AcceptOnceFileListFilter:https://docs.spring.io/spring-integration/docs/5.0.3.RELEASE/reference/html/ftp.html#ftp-inbound :

You can also combine a pattern based filter with other filters, such as an AcceptOnceFileListFilter to avoid synchronizing files that have previously been fetched, by using a CompositeFileListFilter.

关于java - Spring 集成: downloading only new or updated files from FTP server?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49645747/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com