Same file gets picked up again and again in spring-ftp but with different names

邮差的信 提交于 2019-12-24 07:56:19

问题


I have a spring input channel defined like this

<file:inbound-channel-adapter prevent-duplicates="false" id="inpChannel" directory="file:/Users/abhisheksingh/req" auto-startup="true">
        <int:poller id="poller" fixed-delay="1000" />
</file:inbound-channel-adapter>

<int:service-activator input-channel="inpChannel" ref="inpHandler" />

The file name example as TEST.SQQ. SQQ is the file format which the client uses to place the files in ftp. However, I see that the same file is picked up by the spring ftp adapter again and again with different file names. So the first time it is TEST.SQQ. Then the the next time it is TEST.SQQ-20170204.PQQ and then the next time it is TEST.SQQ-20170204.PQQ.20170304.PQQ. This keeps on continuing. I have a filter on my end which checks the name of the file already processed. But since the file name being polled is different each time, all of these files are picked up for processing.

This is my ftp adapter -

<int-ftp:inbound-channel-adapter id="sqqFtpInbound"
    channel="ftpChannel"
    session-factory="sqqFtpClientFactory"
    auto-create-local-directory="true"
    delete-remote-files="false"
    local-filter="acceptAllFileListFilter"
    local-directory="file:/Users/abhisheksingh/ddrive/everge_ws/sqqReq" auto-startup="true" >
    <int:poller id="poller" fixed-delay="1000" />
</int-ftp:inbound-channel-adapter>

Here is my ftp server image -

Here is my local directory image -

I dont understand why the same file gets picked up again and again. I will appreciate some help !

This is my file list filter code.

public class TestFileListFilter<F> extends AbstractFileListFilter<F> {

    private static final Logger log = LoggerFactory.getLogger(EvergeFileListFilter.class);

    @Override
    protected boolean accept(F file) {
        File f = (File) file;
        if(f.getAbsolutePath().contains(".PQQ")) {

            String newDir = "/Users/abhisheksingh/ddrive/sample/pqqReq/";

            String archiveLocation = "/Users/abhisheksingh/ddrive/sample/pqqArchive/";
            String fullName = archiveLocation + f.getName();
            log.info("Check if the file has already been processed " + fullName);

            File fl = new File(fullName);
            final File dir = new File(archiveLocation);
            for (final File child : dir.listFiles()) {

                String archiveName = FilenameUtils.getBaseName(child.getName());
                String inputName = FilenameUtils.getBaseName(fl.getName());
                log.info("Archive file name is " + archiveName);
                log.info("Input file name is " + inputName);
                if(inputName.contains(archiveName)) {
                    log.info("The file is already processed "+inputName);
                }

            }

            if(fl.exists()) {
                log.error("PQQ file has already been processed.");
                removeFile(f);
                return false;
            }else{
                log.info("PQQ File received " + f.getAbsolutePath());
            }
            moveFile(f, newDir);
            return true;
        }
    }

回答1:


I think your custom local-filter has some vulnerabilities to rely on an nonexistent fact to wait for unique files from remote store.

You should ensure that ability because it isn't switched by default.

For this purpose consider to add filter option to the <int-ftp:inbound-channel-adapter> as a reference to the AcceptOnceFileListFilter or FtpPersistentAcceptOnceFileListFilter.

We have a JIRA on the matter.

Please, confirm that it is exactly an issue for you and we might revise a priority for that ticket and will fix it soon.



来源:https://stackoverflow.com/questions/42073373/same-file-gets-picked-up-again-and-again-in-spring-ftp-but-with-different-names

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!