title: Java SSH connection
body: <p>How can I connect to internet server from Java desktop application? I need to access MySQL database and upload/download files. The host that I have (one.com), don't support remote database access, so I've tried with SSH. I don't know anything at all about this. I've tried various codes examples but none of them pass further than connection. I add jsch.jar to my project. Is there something else that I have to add/install or what em I missing?</p>
  
  <pre><code>    public static void main(String args[])
      {
      String user = "user";
      String password = "pass";
      String host = "00.000.00.000";
      int port=22;
  
  String remoteFile="/home/mywebsite.com/test.txt";
  
  try
      {
      JSch jsch = new JSch();
      Session session = (Session) jsch.getSession(user, host, port);
          session.setPassword(password);
          session.setConfig("StrictHostKeyChecking", "no");
      System.out.println("Establishing Connection...");
      session.connect();
          System.out.println("Connection established.");
      System.out.println("Creating SFTP Channel.");
      ChannelSftp sftpChannel = (ChannelSftp) session.openChannel("sftp");
      sftpChannel.connect();
      System.out.println("SFTP Channel created.");
  
  
      InputStream out= null;
      out= sftpChannel.get(remoteFile);
      try (BufferedReader br = new BufferedReader(new InputStreamReader(out)))     {
          String line;
          while ((line = br.readLine()) != null)
              System.out.println(line);
      }
      }
  catch(JSchException | SftpException | IOException e){System.err.print(e);}
  }
  </code></pre>
  
  <p>I get the error:</p>
  
  <pre><code>com.jcraft.jsch.JSchException: java.net.ConnectException: Connection timed out: connect
  BUILD SUCCESSFUL (total time: 24 seconds)
  </code></pre>
  
  <p>Or what other alternatives I have to achieve a remote connection to my site &amp; database?</p>
  
  <p><strong>P.S.</strong> I have tried almost all the example-codes from stackoverflow and all get stuck in the same point ...</p>
  
  <p>Thank you!</p>