3

From reading the Spring SFTP docs (http://docs.spring.io/spring-integration/reference/html/sftp.html) it's not entirely clear if it's possible to prevent redownloading of successfully transferred files which subsequently get removed.

The files being transferred are large and get processed by a local task, and then can be deleted.

However, Spring SFTP is picking up that they have been removed (either at runtime or restart) and redownloading them.

I am already using the SftpPersistentAcceptOnceFileListFilter to survive restarts.

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.

From this, where it mentions local files being removed, I don't know what I should be doing.

Here is my relevant config:

<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>
4

1 回答 1

0

请使用您的配置编辑您的问题 -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);
            }
        }
...
于 2016-05-05T17:23:13.340 回答