title: JSch connect to remote server and sudo su
body: <p>i am new to JSch. please let me know how to connect to remote server and perform sudo su and move file from one path to another inside remote server.</p>
  
  <ol>
  <li>Connect to Remote server : ssh myName@server.remote.com</li>
  <li>sudo su -homeUser</li>
  <li>cp /one/two/testFile.txt /one/testFile.txt</li>
  <li>if found (ls -lrt /one/testFile.txt), echo file copied.</li>
  <li>disconnect</li>
  </ol>
  
  <p>please suggest piece of code to do the above using JSch library</p>
  
  <pre><code>public void exec(){
  Jsch jsch = new JSch();
  try{
  Session session = jsch.getSession(user,host,22);
  session.setPassword("password");
  UserInfo ui = new MyUserInfo();
  session.setUserInfo(ui);
  session.connect();
  Channel channel = session.openChannel("exec");
  ((ChannelExec) channel).setCommand("sudo su -homeUser");
  
  Channel.connect();
  Channel.disconnect();
  
  
  
  session.disconnect();
  }Catch(Exception e )
  {
  }
  }
  public static class MyuserInfo implements Userinfo
  {
  
  @override
  public String getPassword()
  {
  return "password";
  }
  @override
  public String getPaspharse(){
  return "yes";
  }
  
  @override
  public boolean promtPassword(String arg0)
  {
  return true;
  }
  @override
  public boolean promtPasspharse(String arg0)
  {
  return true;
  }
  
  @override
  public boolean promtYesorNo(String arg0)
  {
  return true;
  }
  @override
  public boolean showMessage(String arg0)
  {
  
  }
  }
  </code></pre>