java - Spring集成SFTP - 不会重新下载本地删除的文件

标签 java spring spring-integration spring-integration-sftp

通过阅读 Spring SFTP 文档 ( http://docs.spring.io/spring-integration/reference/html/sftp.html ),并不完全清楚是否可以防止重新下载成功传输的文件,这些文件随后会被删除。

正在传输的文件较大,需要通过本地任务处理,然后才能删除。

但是,Spring SFTP 发现它们已被删除(在运行时或重新启动时)并重新下载它们。

我已经在使用 SftpPersistentAcceptOnceFileListFilter 来保证重新启动后仍能正常运行。

The above discussion refers to filtering the files before retrieving them. Once the files have been retrieved, an additional filter is applied to the files on the file system. By default, this is anAcceptOnceFileListFilter which, as discussed, retains state in memory and does not consider the file’s modified time. Unless your application removes files after processing, the adapter will re-process the files on disk by default after an application restart.

Also, if you configure the filter to use a FtpPersistentAcceptOnceFileListFilter, and the remote file timestamp changes (causing it to be re-fetched), the default local filter will not allow this new file to be processed.

Use the local-filter attribute to configure the behavior of the local file system filter. To solve these particular use cases, you can use a FileSystemPersistentAcceptOnceFileListFilter as a local filter instead. This filter also stores the accepted file names and modified timestamp in an instance of theMetadataStore strategy (Section 9.5, “Metadata Store”), and will detect the change in the local file modified time.

从这里,它提到本地文件被删除,我不知道我应该做什么。

这是我的相关配置:

<int-sftp:inbound-channel-adapter id="sftpInboundAdapter"
        auto-startup="true" channel="receiveChannel" session-factory="sftpSessionFactory"
        local-directory="file:local-dir" remote-directory="files"
        auto-create-local-directory="true" delete-remote-files="false"
        filter="compositeFilter">
        <int:poller fixed-rate="1000" max-messages-per-poll="1" />
    </int-sftp:inbound-channel-adapter>

<bean id="compositeFilter"
        class="org.springframework.integration.file.filters.CompositeFileListFilter">
        <constructor-arg>
            <list>
                <bean
                    class="org.springframework.integration.sftp.filters.SftpSimplePatternFileListFilter">
                    <constructor-arg value="*.zip" />
                </bean>
                <bean
                    class="org.springframework.integration.sftp.filters.SftpPersistentAcceptOnceFileListFilter">
                    <constructor-arg name="store" ref="metadataStore" />
                    <constructor-arg value="foo/bar" />
                </bean>
            </list>
        </constructor-arg>
    </bean>

最佳答案

请使用您的配置编辑您的问题 - SftpPersistentAcceptOnceFileListFilter 应防止重新下载文件,除非文件上的时间戳发生更改。

F[] files = session.list(remoteDirectory);
if (!ObjectUtils.isEmpty(files)) {
    List<F> filteredFiles = filterFiles(files);
    for (F file : filteredFiles) {
        try {
            if (file != null) {
                copyFileToLocalDirectory(
                        remoteDirectory, file, localDirectory,
                        session);
            }
        }
...

关于java - Spring集成SFTP - 不会重新下载本地删除的文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37056114/

相关文章:

java - Java Class.cast() 与普通转换相比的效率?

java - Spring 集成 SFTP - 传输后处理

java - 使用原生SQL查询时如何指定数据类型?

java - Hibernate 方言未定义错误

error-handling - 应用程序运行时异常未发送到 errorChannel 或 ServiceActivator 无法监听 errorChannel

java - 将 Spring Integration executorChannel 与 Spring Cloud Function 结合使用

java - 项目编译后 map 不显示

java - 从 HTML 网页读取 URL 并将其写入文件

java - 将Java连接到MySQL数据库

java - 在签名的 jar 中使用 Java 配置