gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 12:32:45 24 4
gpt4 key购买 nike

通过阅读 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/

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