HungryandConfused
HungryandConfused

Reputation: 11

Spring SFTP & file outbound gateway chain

new to Spring and could use some help on figuring out how to correctly chain together an sftp outbound gateway with a file outbound gateway. I want to confirm a file has sftp'ed, and then move it to an archive location.

Essentially, I have a directory where files are sent to be sftp'd somewhere else. The file is then supposed to be moved to an Archive directory, after the file has been transferred.

Each code piece works independently, but fails when I attempt to connect the two. I am unable to use the reply channel that I would normally because the reply channel confirms where the file has been saved to remotely, and that .msg is moved to the archive directory.

I suspect that order does not do what I think it does.

Currently, the file moves 90% of the time to the archive directory, without sftping the file.

Is this possible, or am I just barking up the wrong tree? Is there a way to configure the sftp:outbound-gateway downstream, or should I try using a different method?

<!-- START: SFTP files-->   
    <int-file:inbound-channel-adapter 
    directory="file:${sftp.repo}"       
    channel="SFTPchannel"
    prevent-duplicates="false" 
    ignore-hidden="true" />

    <int-sftp:outbound-gateway 
    session-factory="SFTPFactory"
    request-channel="SFTPchannel" 
    order="1"
    command="mput" 
    command-options="-1"
    expression="payload"
    mode="REPLACE"
    use-temporary-file-name="false"
    remote-filename-generator="filenameGenerator"
    auto-create-directory="false"
    remote-directory="${sftp.remote.destination}"/>

    <int-file:outbound-gateway 
    request-channel="SFTPchannel" 
    order="2" 
    directory-expression="'${repository.directory}/'+new java.text.SimpleDateFormat('yyyyMMdd').format(new java.util.Date())" 
    mode="REPLACE" 
    auto-create-directory="true"
    filename-generator="filenameGenerator"
    delete-source-files="true" 
    reply-channel="nullChannel" />
<!-- END: SFTP files--> 

Upvotes: 1

Views: 1005

Answers (1)

Gary Russell
Gary Russell

Reputation: 174769

See the retry-and-more sample, and particularly the Expression Evaluating Advice Demo therein. It covers your exact use case.

Upvotes: 1

Related Questions