title: Spring Integration - outbound transfer renaming issues
body: <p>I am using the sample program <a href="https://github.com/spring-projects/spring-integration-samples/blob/master/basic/sftp/src/test/resources/META-INF/spring/integration/SftpOutboundTransferSample-context.xml" rel="nofollow">here</a> to build my code. Everything works fine with the local SFTP test server, When I tested today in my client SFTP servers, it gave me an exception as below. </p>
  
  <p>When I debugged I saw the file being written with '.writing' extension on the client's SFTP server. The contents are fine, I don't see any issues with the file that was transferred but the file name is the issue now. After reading through the <a href="http://docs.spring.io/spring-integration/reference/html/sftp.html#sftp-inbound" rel="nofollow">spring docs</a>, I see that this is the temporary file extension, and the program tries to rename it back to the original name, but since the client SFTP does not provide this option, it throws and exception. </p>
  
  <p>I tried writing the <code>temporary-file-suffix=".writing"</code> as <code>temporary-file-suffix=""</code> thinking that will set the options off, alas the same issue. Is there a work around?</p>
  
  <p>One of the <a href="http://forum.spring.io/forum/spring-projects/integration/119697-unable-to-rename-file-in-sftp-remote-directory-please-help" rel="nofollow">post</a> mentions this, but no solution or the issue vanished for the user.</p>
  
  <pre><code>&gt; 2014-07-28 20:11:21,564 [main] INFO  com.jcraft.jsch - SSH_MSG_NEWKEYS
  &gt; sent 2014-07-28 20:11:21,608 [main] INFO  com.jcraft.jsch -
  &gt; SSH_MSG_NEWKEYS received 2014-07-28 20:11:21,678 [main] INFO 
  &gt; com.jcraft.jsch - SSH_MSG_SERVICE_REQUEST sent 2014-07-28 20:11:21,770
  &gt; [main] INFO  com.jcraft.jsch - SSH_MSG_SERVICE_ACCEPT received
  &gt; 2014-07-28 20:11:21,818 [main] INFO  com.jcraft.jsch - Authentications
  &gt; that can continue: publickey,keyboard-interactive,password 2014-07-28
  &gt; 20:11:21,818 [main] INFO  com.jcraft.jsch - Next authentication
  &gt; method: publickey 2014-07-28 20:11:21,819 [main] INFO  com.jcraft.jsch
  &gt; - Authentications that can continue: keyboard-interactive,password 2014-07-28 20:11:21,819 [main] INFO  com.jcraft.jsch - Next
  &gt; authentication method: keyboard-interactive 2014-07-28 20:11:21,978
  &gt; [main] INFO  com.jcraft.jsch - Authentication succeeded
  &gt; (keyboard-interactive). 2014-07-28 20:11:22,199 [main] DEBUG
  &gt; org.springframework.beans.factory.support.DefaultListableBeanFactory -
  &gt; Returning cached instance of singleton bean
  &gt; 'integrationEvaluationContext' 2014-07-28 20:11:22,878 [main] DEBUG
  &gt; org.springframework.integration.sftp.session.SftpSession - Initial
  &gt; File rename failed, possibly because file already exists. Will attempt
  &gt; to delete file: remote/TESTFILE.ABC and execute rename again.
  &gt; 2014-07-28 20:11:22,958 [main] INFO  com.jcraft.jsch - Disconnecting
  &gt; from fsgatewaytest.aexp.com port 22 2014-07-28 20:11:22,961 [Connect
  &gt; thread fsgatewaytest.aexp.com session] INFO  com.jcraft.jsch - Caught
  &gt; an exception, leaving main loop due to Socket closed Exception in
  &gt; thread "main" org.springframework.messaging.MessageDeliveryException:
  &gt; Error handling message for file [data/TESTFILE.ABC -&gt; TESTFILE.ABC]
  &gt;   at
  &gt; org.springframework.integration.file.remote.RemoteFileTemplate$1.doInSession(RemoteFileTemplate.java:227)
  &gt;   at
  &gt; org.springframework.integration.file.remote.RemoteFileTemplate$1.doInSession(RemoteFileTemplate.java:190)
  &gt;   at
  &gt; org.springframework.integration.file.remote.RemoteFileTemplate.execute(RemoteFileTemplate.java:302)
  &gt;   at
  &gt; org.springframework.integration.file.remote.RemoteFileTemplate.send(RemoteFileTemplate.java:190)
  &gt;   at
  &gt; org.springframework.integration.file.remote.RemoteFileTemplate.send(RemoteFileTemplate.java:182)
  &gt;   at
  &gt; org.springframework.integration.file.remote.handler.FileTransferringMessageHandler.handleMessageInternal(FileTransferringMessageHandler.java:101)
  &gt;   at
  &gt; org.springframework.integration.handler.AbstractMessageHandler.handleMessage(AbstractMessageHandler.java:78)
  &gt;   at
  &gt; org.springframework.integration.dispatcher.AbstractDispatcher.tryOptimizedDispatch(AbstractDispatcher.java:116)
  &gt;   at
  &gt; org.springframework.integration.dispatcher.UnicastingDispatcher.doDispatch(UnicastingDispatcher.java:101)
  &gt;   at
  &gt; org.springframework.integration.dispatcher.UnicastingDispatcher.dispatch(UnicastingDispatcher.java:97)
  &gt;   at
  &gt; org.springframework.integration.channel.AbstractSubscribableChannel.doSend(AbstractSubscribableChannel.java:77)
  &gt;   at
  &gt; org.springframework.integration.channel.AbstractMessageChannel.send(AbstractMessageChannel.java:255)
  &gt;   at
  &gt; org.springframework.integration.channel.AbstractMessageChannel.send(AbstractMessageChannel.java:223)
  &gt;   at
  &gt; com.reachlocal.payment.integration.SftpOutboundTransferMain.main(SftpOutboundTransferMain.java:43)
  &gt; Caused by: org.springframework.messaging.MessagingException: Failed to
  &gt; write to 'inbox/REACHLOCALTST.CUFI.writing' while uploading the file
  &gt;   at
  &gt; org.springframework.integration.file.remote.RemoteFileTemplate.sendFileToRemoteDirectory(RemoteFileTemplate.java:397)
  &gt;   at
  &gt; org.springframework.integration.file.remote.RemoteFileTemplate.access$500(RemoteFileTemplate.java:56)
  &gt;   at
  &gt; org.springframework.integration.file.remote.RemoteFileTemplate$1.doInSession(RemoteFileTemplate.java:213)
  &gt;   ... 13 more Caused by: org.springframework.core.NestedIOException:
  &gt; Failed to delete file inbox/TESTFILE.ABC; nested exception is
  &gt; org.springframework.core.NestedIOException: Failed to remove file: 2:
  &gt; Specified file path is invalid.   at
  &gt; org.springframework.integration.sftp.session.SftpSession.rename(SftpSession.java:200)
  &gt;   at
  &gt; org.springframework.integration.file.remote.RemoteFileTemplate.sendFileToRemoteDirectory(RemoteFileTemplate.java:393)
  &gt;   ... 15 more Caused by: org.springframework.core.NestedIOException:
  &gt; Failed to remove file: 2: Specified file path is invalid.     at
  &gt; org.springframework.integration.sftp.session.SftpSession.remove(SftpSession.java:83)
  &gt;   at
  &gt; org.springframework.integration.sftp.session.SftpSession.rename(SftpSession.java:194)
  &gt; ... 16 more
  </code></pre>
  
  <p>Updated config: Using use-temporary-file-name="false" solved this issue. Thanks a ton.</p>
  
  <pre><code>&lt;int:channel id="inputChannel"/&gt;
  
  &lt;int-sftp:outbound-channel-adapter id="sftpOutboundAdapter"
              session-factory="sftpSessionFactory"
              channel="inputChannel"
              remote-filename-generator-expression="payload.getName()"
              remote-directory="inbox"
              use-temporary-file-name="false"/&gt;
  </code></pre>