title: How to open a path in remote machine and write a file in that path using java
body: <p>Based on user input data and database data, i need to create a file and place it in remote machine. So the better way i could think of was connect to remote machine and write the file directly there. So far using <code>JSch</code> i connected to remote machine. but i have no idea how to write a file in a particular location <code>(root/usr/path/)</code> in this path i need to write and place a file <code>(ddr12213124.NEW or ddr12213124.CSV)</code>.</p>
  
  <p>I have attached the code for connecting to remote machine</p>
  
  <pre><code>package com.trial.classes;
  
  import java.io.InputStream;
  
  import com.jcraft.jsch.Channel;
  import com.jcraft.jsch.ChannelSftp;
  import com.jcraft.jsch.JSch;
  import com.jcraft.jsch.JSchException;
  import com.jcraft.jsch.Session;
  import com.jcraft.jsch.SftpException;
  import com.jcraft.jsch.UserInfo;
  
  public class transferFile {
  
      public static void main(String[] args) {
          // TODO Auto-generated method stub
          JSch jsch = new JSch();
          Session session = null;
          try {
              session = jsch.getSession("ragesh", "10.0.0.1", 22);
              session.setConfig("StrictHostKeyChecking", "no");
              session.setPassword("password");
              session.connect();
              System.out.println("Connected to session successfully");
              Channel channel = session.openChannel("sftp");
              channel.connect();
              System.out.println("Connected to Channel successfully");
              ChannelSftp sftpChannel = (ChannelSftp) channel;
  
              sftpChannel.exit();
              session.disconnect();
          } catch (JSchException e) {
              e.printStackTrace();  
          }
      }
  }
  </code></pre>
  
  <p>Now i would like to create a file <code>(ddr12213124.NEW or ddr12213124.CSV)</code> and place it in the path <code>root/usr/path/</code></p>
  
  <p>I asked this question earlier but it was marked duplicate and i was asked to raise a new question. This is not duplicate. No appropriate answer was found so far in the link that was posted earlier. </p>