Steve
Steve

Reputation: 4681

Spring integration how can I move a file after FTP'ing it?

I am using Spring Integration to FTP a file. After I've processed that file though I'd like to move the file from the FTP directory, to an archive directory on the FTP server. How can I do this?

I had figured the solution might involve enriching the method header with the filename, but it doesn't look like the streaming channel adapter makes that available (since it's just a stream and not a File/Path).

<int-ftp:inbound-streaming-channel-adapter
    auto-startup="true" id="ftpListener2" channel="ftpChannel"
    session-factory="ftpSessionFactory" remote-directory="/data/crp/prd/ald/01/stuff/archive"
    filename-pattern="ADX_I.2017083100100.tar.gz">
    <integration:poller fixed-rate="5000"
        max-messages-per-poll="-1" />
</int-ftp:inbound-streaming-channel-adapter>

Upvotes: 0

Views: 797

Answers (1)

Artem Bilan
Artem Bilan

Reputation: 121202

The message returned from the Streaming Channel Adapter is like this:

 return getMessageBuilderFactory()
                    .withPayload(session.readRaw(remotePath))
                    .setHeader(IntegrationMessageHeaderAccessor.CLOSEABLE_RESOURCE, session)
                    .setHeader(FileHeaders.REMOTE_DIRECTORY, file.getRemoteDirectory())
                    .setHeader(FileHeaders.REMOTE_FILE, file.getFilename())
                    .setHeader(FileHeaders.REMOTE_FILE_INFO,
                            this.fileInfoJson ? file.toJson() : file)
                    .build();

So, you have all the info related to the remote file.

So, you definitely can use <int-ftp:outbound-gateway> to perform MV command with that info in the headers of the request message.

Upvotes: 1

Related Questions