1
votes

I have a file in remote FTP, say "abc.txt". This file will be updated for every minute. I have configured my FTP Inbound Channel Adapter to retrieve the same file for every minute.

This works fine for the first time (i.e. the local directory is still empty). However, for the 2nd time onward, the intermediate file abc.txt.writing cannot replace the original abc.txt file. In other words, both the abc.txt (old version) and abc.txt.writing will coexist in the same directory. (with the new version data). (No error prompt)

Am I hitting a bug or I have to set some parameter such that the old version of file will be deleted first such that the abc.txt.writing could be successfully renamed.

<bean id="ftpSessionFactory"
      class="org.springframework.integration.ftp.session.DefaultFtpSessionFactory"
      p:host="127.0.0.1"
      p:port="21"
      p:username="myusername"
      p:password="mypassword">

<bean id="cachingSessionFactory" class="org.springframework.integration.file.remote.session.CachingSessionFactory">
        <constructor-arg ref="ftpSessionFactory" />
        <constructor-arg value="1" />
        <property name="sessionWaitTimeout" value="1000" />
</bean>

<int-ftp:inbound-channel-adapter id="myChannel"
                                     channel="nullChannel"
                                     session-factory="cachingSessionFactory"
                                     filename-pattern="abc.txt"
                                     remote-directory="/"
                                     preserve-timestamp="true"
                                     local-directory="c:/temp">
    <int:poller cron="15 * * * * ?" max-messages-per-poll="1" />
</int-ftp:inbound-channel-adapter>



c:\temp> dir /a
06/23/2017  11:44 AM           840,000 abc.txt
06/23/2017  11:45 AM           840,000 abc.txt.writing
1
How about using int-ftp:outbound-channel-adapter instead of int-ftp:inbound-channel-adapter? Because int-ftp:outbound-channel-adapter has an attribute mode="REPLACE" using which you can get what you desired. The condition is that you should use spring integration version 4.1 or above.Ashok.N
I am using SI 4.3.10. I am downloading a file from FTP and process it locally in downstream components (I didn't post the process code for the downstream components in the above code snippet). FTP Outbound Channel Adapter doesn't help me for this case.user3544765
Perhaps your downstream code is leaving the old file in-use, preventing the rename operation from succeeding. You could also remove the file in that downstream processing.Gary Russell
Gary, I have tried to remove the downstream code (I have tested using with the channel changed to nullChannel in ftp:inbound-channel-adapter) but the issue persist. The only way right now is I have to remove the old file after processing (I moved the download file to another directory for processing). But I think it should allow me to overwrite the old file, rather than keep the intermediate .writing file without any error message.user3544765
Originally, I want to use the single directory for download and processing (I will generate the delta content files based on the last image and current image).user3544765

1 Answers

1
votes

The FileWritingMessageHandler has deleteSourceFiles option which is false by default. That is for case if you use <int-file:outbound-channel-adapter>.

If you deal with local file somehow other way, e.g. <service-activator>, you should consider to use ExpressionEvaluatingRequestHandlerAdvice and perform File.delete() on success:

<int:request-handler-advice-chain>
        <bean class="org.springframework.integration.handler.advice.ExpressionEvaluatingRequestHandlerAdvice">
            <property name="onSuccessExpressionString" value="payload.delete()"/>
        </bean>
    </int:request-handler-advice-chain>

Where that payload is exactly a local File as a result of the <int-ftp:inbound-channel-adapter>.