【问题标题】:Spring Integration: downloading only new or updated files from FTP server?Spring Integration:仅从 FTP 服务器下载新文件或更新文件?
【发布时间】:2018-04-04 19:20:00
【问题描述】:

我正在使用 Spring Integration 编写 FTP-Client 以从远程 FTP-Server 获取文件。此服务必须下载超大文件,因此多次下载同一个文件并不是最佳选择。

这是我的配置:

@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 匹配的所有文件还是刚刚更改过的文件?

【问题讨论】:

    标签: java spring kotlin spring-integration


    【解决方案1】:

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

    您还可以使用CompositeFileListFilter 将基于模式的过滤器与其他过滤器(例如AcceptOnceFileListFilter)结合起来,以避免同步之前提取的文件。

    【讨论】:

      猜你喜欢
      • 2015-07-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-06-23
      • 2012-07-30
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多