how to get file with int-ftp:outbound-gateway and

2019-09-08 01:29发布

问题:

thanks for attention
i used int-ftp:outbound-gateway with mget command, i want to when retrieve file from server if file that retrieve from server exists in local directory then thrown bellow exception :

org.springframework.messaging.MessagingException: Local file .\backup\a\in\a.in already exists

adapter code is:

<int-ftp:outbound-gateway id="gatewayGET"
                              local-directory-expression="'./backup/' +#remoteDirectory"
                              session-factory="ftpSessionFactory"
                              request-channel="toGet"
                              reply-channel="toRemoveChannel"
                              command="mget"
                              command-options="-R"
                              expression="payload.remoteDirectory + '/' + payload.filename"/>

thans for help me.

回答1:

There's currently no way to ignore the error when a file already exists locally, please open a new feature JIRA issue and we can add an option to the gateway.

In the meantime, one workaround I can think of is to mget them to a temporary directory and use a file outbound channel adapter to "move" the file to the final directory - it has an option to overwrite (replace) any existing file, while removing the temporary file.

Or, you can use LS to get the file names, remove them, and then do the mget.