title: How do I transfer a file from one directory to another using Java SFTP Library JSch?
body: <p>I need to program a file transfer using JSch library. I have a simple directory with two folders -</p>
  <p><a href="https://i.stack.imgur.com/UrqAN.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/UrqAN.png" alt="enter image description here" /></a></p>
  <p>In the <code>SFTP_1</code> folder, I have a bitmap image.  And the <code>SFTP_2</code> folder is just an empty folder.  My goal is to transfer  the image using SFTP from SFTP_1 to SFTP_2 .</p>
  <p>Here is my code thus far :</p>
  <pre><code>FileTransfer fileTransfer = new FileTransfer();              
        
  JSch jsch = new JSch();
  
  String host = &quot;127.0.0.1&quot;;
  int port = 22;
  
  String user = &quot;user&quot;;
  Session session = jsch.getSession(user, host, port);      
  session = jsch.getSession(&quot;username&quot;, &quot;127.0.0.1&quot;, 22);
  session.connect();
  
  ChannelSftp sftp = null;
  sftp = (ChannelSftp)session.openChannel(&quot;sftp&quot;) ; //channel;
  
  sftp.rename(
      &quot;C:\\Users\\ADMIN\\Desktop\\Work\\ConnectOne_Bancorp\\Java_Work\\SFTP_1\\house.bmp&quot;,
      &quot;C:\\Users\\ADMIN\\Desktop\\Work\\ConnectOne_Bancorp\\Java_Work\\SFTP_2\\house.bmp&quot;);
  session.disconnect();
  </code></pre>
  <p>What I would like to do is to simply transfer a file from one directory in my machine, to another directory. any tips appreciated, thanks !</p>