title: SFTP error : com.jcraft.jsch.JSchException: invalid server's version string
body: <p>I have the below code to SFTP to a location</p>
  
  <pre class="lang-java prettyprint-override"><code>public static void putFile(String username, String host, String password, String remotefile,     String localfile){
      JSch jsch = new JSch();
      Session session = null;
      try {
            session = jsch.getSession(username, host, 22);
            session.setConfig("StrictHostKeyChecking", "no");
            session.setPassword(password);
            session.connect();
  
            Channel channel = session.openChannel("sftp");
            channel.connect();
            ChannelSftp sftpChannel = (ChannelSftp) channel;
            sftpChannel.put(localfile, remotefile);
            sftpChannel.exit();
            session.disconnect();
       } catch (JSchException e) {
            e.printStackTrace();  
       } catch (SftpException e) {
            e.printStackTrace();
       }
  }
  </code></pre>
  
  <p>I am able to SFTP the document from my local machine using the above code. However when I am trying from a different environment to SFTP to the same location I am getting the follow error.</p>
  
  <blockquote>
    <p>com.jcraft.jsch.JSchException: <strong>invalid server's version string</strong> at<br>
    com.jcraft.jsch.Session.connect(Session.java:253)</p>
  </blockquote>
  
  <p>Note : I am using <strong>jsch-0.1.31.jar</strong> file.</p>
  
  <p>on printing out <code>session.getClientVersion()</code> I am getting <strong>"SSH-2.0-JSCH-0.1.31"</strong>.</p>
  
  <p>I tried to upgrade the jar file to <strong>jsch-0.1.51.jar</strong> then <code>session.getClientVersion()</code> = <strong>"SSH-1.5-JSCH-0.1.51"</strong> and I am getting the following error</p>
  
  <blockquote>
    <p>com.jcraft.jsch.JSchException: Session.connect: java.net.SocketException: <strong>Connection reset</strong> at com.jcraft.jsch.Session.connect(Session.java:558)</p>
  </blockquote>
  
  <p>Please can you help me on what parameters should I be looking into and what is causing it to run from my local machine and upload to the same SFTP location and not from other environment?</p>