title: Spring Integration: Move file in remote SFTP location after processing
body: <p>I have a condition where I should read the file from SFTP remote location with the following steps:</p>
  
  <ol>
  <li><p>Read file from SFTP location say <code>input</code> folder.</p></li>
  <li><p>Process file and call a REST API with the content of file.</p></li>
  <li><p>If the call is successful move the remote SFTP file to <code>archive</code>
  folder else move the remote SFTP file to <code>error</code> folder.</p></li>
  </ol>
  
  <p>I am thinking of two approaches. I don't know which are possible.</p>
  
  <p>First, read the file from SFTP remote location to local and delete it from remote. Then call the REST API. According to response of REST call, success or error upload the file to remote folder.</p>
  
  <p>Second, read the file from SFTP remote location to local. Then call the REST API. According to response of REST call, success or error upload the file to remote folder.</p>
  
  <p>Can anyone enlighten me which of the approach is possible and convenient? I would appreciate if you can mention the channel adapters as well. </p>
  
  <p>So far I am able to call REST API.</p>
  
  <pre><code>&lt;int-sftp:inbound-channel-adapter id="sftpInbondAdapter"
          auto-startup="true" 
          channel="receiveChannel" 
          session-factory="sftpSessionFactory"
          local-directory="${local.dir}" 
          remote-directory="${sftp.dir.input}"
          auto-create-local-directory="true" 
          delete-remote-files="true"
          filename-pattern="*.txt"&gt;
          &lt;int:poller fixed-rate="60000" max-messages-per-poll="1" /&gt;
      &lt;/int-sftp:inbound-channel-adapter&gt;
      &lt;int:channel id="receiveChannel"/&gt;
  
      &lt;int:splitter input-channel="receiveChannel" output-channel="singleFile"/&gt;
      &lt;int:channel id="singleFile"/&gt;
  
      &lt;int:service-activator input-channel="singleFile"
          ref="sftpFileListenerImpl" method="processMessage" output-channel="costUpdate" /&gt;
      &lt;int:channel id="costUpdate" /&gt; 
  
       &lt;int:header-enricher input-channel="costUpdate" output-channel="headerEnriched"&gt;
           &lt;int:header name="content-type" value="application/json" /&gt;
       &lt;/int:header-enricher&gt;
       &lt;int:channel id="headerEnriched" /&gt;
  
       &lt;int-http:outbound-gateway
          url="${cost.center.add.rest.api}" request-channel="headerEnriched"
          http-method="POST" expected-response-type="java.lang.String" reply-channel="costAdded" &gt;
      &lt;/int-http:outbound-gateway&gt;
      &lt;int:publish-subscribe-channel id="costAdded" /&gt;
  </code></pre>
  
  <p>I want to move the remote file to another location in remote folder once the API call is success after evaluating the API call response. My question is how do I move the remote file to another remote location based on the response of <code>http:outbound-gateway</code>?</p>