1
votes

I have successfully set up Spring with SFTP integration, and am polling an SFTP server and pulling down files.

What I would like to know, is it possible for a task to be fired on each file once it's download has completed? I don't want to go down the road of filesystem watches - is there something built into Spring SFTP for this?

Having looked at the documentation, it looks like it can be achieved with Channels.

This is what my receiver channel currently looks like:

<int:channel id="receiveChannel">
    <int:queue />
</int:channel>

I'm not sure what I need to do to fire a customer interceptor or similar.

Edit: from the Spring docs it says this:

It is also important to understand that SFTP Inbound Channel Adapter is a Polling Consumer and therefore you must configure a poller (either a global default or a local sub-element). Once the file has been transferred to a local directory, a Message with java.io.File as its payload type will be generated and sent to the channel identified by the channel attribute.

I'm not sure how to implement this - and can't find any examples.

2

2 Answers

1
votes

Looks like you have to start from the beginning of Enterprise Integration Patterns and determine for yourself that channel is the most important first class citizen in the integration.

So, you have an <int-sftp:inbound-channel-adapter>, which responsibility to poll entities from the remote directory, turn them to the java.io.File (like you noticed in the RTFM) and send as a payload of Message to the configured channel. The subscriber for that channel will pick up the message and do some desired process under that File payload.

See also Spring Integration Samples for more information.

0
votes

For the benefit of others who come across this, the issue is that the messages are put on the received channel only when ALL files have been transferred. They are not handled one at a time (as I had expected). In my case I have thousands of large files on a remote SFTP server, and only after all of them downloaded were the messages sent to the receiver channel.

I'm not sure if this is by design.