title: cant establish connection with jsh java
body: <p>Hello everone im trying to make a java program that will connect to ssh server and then read username and password from file and type the correct combos to a new file , however I'm getting an error saying <code>com.jcraft.jsch.JSchException: timeout: socket is not established</code> am I supposed to download something in addition to running the code? or is the code supposed to make a connection by itself? Thanks for the help</p>
  <pre><code>package javaapplication3;
  import com.jcraft.jsch.Channel;
  import com.jcraft.jsch.ChannelExec;
  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 java.io.File;
  import java.io.FileNotFoundException;
  import java.io.FileWriter;
  import java.io.IOException;
  import java.io.InputStream;
  import java.io.InputStreamReader;
  import java.io.PrintWriter;
  import java.io.UnsupportedEncodingException;
  import java.util.Scanner;
  import java.util.logging.Level;
  import java.util.logging.Logger;
  
  
  /**
   * @author World
   */
  public class JavaApplication3 {
  
      public static void main(String args[]) throws UnsupportedEncodingException {
          String user = &quot;john&quot;;
          String password = &quot;123&quot;;
          String host = &quot;192.168.100.23&quot;;
          int port = 22;
          String remoteFile = &quot;pass.txt&quot;;
  
          try {
              JSch jsch = new JSch();
              Session session = jsch.getSession(user, host, port);
              session.setPassword(password);
              session.setConfig(&quot;StrictHostKeyChecking&quot;, &quot;no&quot;);
              System.out.println(&quot;Establishing Connection...&quot;);
              
  session.setTimeout(20000);
              session.connect();
              System.out.println(&quot;Connection established.&quot;);
              System.out.println(&quot;Crating SFTP Channel.&quot;);
              ChannelSftp sftpChannel = (ChannelSftp) session.openChannel(&quot;sftp&quot;);
              sftpChannel.connect();
              System.out.println(&quot;SFTP Channel created.&quot;);
  
              InputStream inputStream = sftpChannel.get(remoteFile);
  
              try (Scanner scanner = new Scanner(new InputStreamReader(inputStream))) {
                  while (scanner.hasNextLine()) {
                      String line = scanner.nextLine();
                       String[] sArray = line.split(&quot;,&quot;);
                         System.out.println(sArray[0]); //Just to verify that file is being read
                System.out.println(sArray[1]);
                         if (user == sArray[0] &amp;&amp; password == sArray[1]){
                
      File file = new File (&quot;C:/Users/Me/Desktop/directory/file.txt&quot;);
      PrintWriter printWriter = null;
                          try {
                              printWriter = new PrintWriter (&quot;file.txt&quot;);
                          } catch (FileNotFoundException ex) {
                              Logger.getLogger(JavaApplication3.class.getName()).log(Level.SEVERE, null, ex);
                          }
      printWriter.println (&quot;hello&quot;);
      printWriter.close ();  
                
             
                }
                else
                {
                  System.out.println(line);
                }
                    
                      
                  }
              }
          } catch (JSchException | SftpException e) {
              e.printStackTrace();
          }
      }
  }
  </code></pre>