title: How do I authenticate programmatically using jsch?
body: <p>I want to upload a file to a remote server via sftp.  I am using the Jsch library.  The code below works, but I always have to enter the username and password via the output console, even though I've set those values in the Session object.  Every example I've seen on Stack Overflow and on the Jsch example <a href="http://www.jcraft.com/jsch/examples/" rel="noreferrer">page</a> requires user input.  Is there a way to pass the password programmatically? (I am required to authenticate via username/password.  I cannot use SSH keys...)</p>
  
  <pre><code>    JSch jsch = new JSch();
      ChannelSftp sftpChannel;
      Session session;
      Channel channel;
      OutputStream os;
  
      try {
  
          session = jsch.getSession("myUsername", "myHost", 22);
          session.setPassword("myPassword");
          session.setConfig("StrictHostKeyChecking", "no");
          session.connect();
  
          channel = session.openChannel("sftp");
          channel.connect();
          sftpChannel = (ChannelSftp) channel;
          os = sftpChannel.getOutputStream();
  
      } catch (Exception e) {
      }
  </code></pre>