title: How to perform scp between 2 remote unix boxes using Jsch?
body: <p>I am writing a Java code using Jsch in which I need to perform scp between 2 remote UNIX boxes. </p>
  
  <p>I tried to execute the scp command in the same way as to execute a normal command from my java code like this :</p>
  
  <pre><code>JSch jsch=new JSch();
  Session session=jsch.getSession("user", "host", 22);
  UserInfo ui=new MyUserInfo();
  session.setUserInfo(ui);
  session.setPassword("pwd");
  session.connect();
  Channel channel=session.openChannel("exec");
  ((ChannelExec)channel).setCommand("scp user@mademo.org:/home/user/demo.csv /home/user/demo.csv");
  channel.setInputStream(null);
  ((ChannelExec)channel).setErrStream(System.err);
  InputStream in=channel.getInputStream();
  channel.connect();
  //Printing operations
  channel.disconnect();
  session.disconnect();
  </code></pre>
  
  <p>Instead of prompting password for user@mademo.org as I expected. I get only errors :</p>
  
  <pre><code>Permission denied, please try again.
  Permission denied, please try again.
  Permission denied (publickey,gssapi-with-mic,password).
  exit-status: 1
  </code></pre>
  
  <p>From executing the command on the UNIX box directly, I have found this :</p>
  
  <p>scp asks for password to connect to the remote machine.. however using this code, it is not prompting for any password. So it is trying to perform scp without the password and trying thrice(NumberoOFAttempts flag) and gives the error messages...</p>
  
  <p>I want to know how to make scp atleast prompt to enter something instead of just not taking password ... I have used the default implementation of MyUserInfo class given in jsch examples for my code...</p>
  
  <p>Or </p>
  
  <p>Is there any way to provide the password along with the scp command ?? I am trying to avoid using private/public key combinations as much as possible..</p>
  
  <p>EDIT : 
  From Paulo's post.. Now I have added channel.setPty(true) to get a pseudo terminal for the command and it is asking for me to enter Password than failing automatically..</p>
  
  <p>How should I specify the password now... I tried typing it in the console but it is not accepting and keeps on waiting for user input.... I tried setting it using channel.setInputStream(pwdbytes); but it keeps waiting at the command and not taking the input ..</p>
  
  <p>Thanks for any help regarding this...</p>