title: SFTP connection error: connection timeout
body: <p>I'm trying to connect to SFTP server using <code>jsch</code> library. This is how I do:</p>
  
  <pre><code>public class SFTPConnection {
  
      private String sftpHost;
      private String sftpUser;
      private String sftpPass;
      private String sftpWorkDir;
      private Session session = null;
      private Channel channel = null;
      private ChannelSftp channelSftp = null;
  
      static final String SFTPHOST = "prod-sftp.host.ru";
      static final String SFTPUSER = "user";
      static final String SFTPPASS = "pass";
      static final String SFTPWORKINGDIRINC = "/dir/Port_Increment/";
      static final String SFTPWORKINGDIRFULL = "/dir/Port_All_Full/";
  
      public  SFTPConnection(String sftpHost, String sftpUser, String sftpPass, String sftpWorkDir) throws JSchException, SftpException {
          this.sftpHost = sftpHost;
          this.sftpUser = sftpUser;
          this.sftpPass = sftpPass;
          this.sftpWorkDir = sftpWorkDir;
  
          JSch jsch = new JSch();
  
          session = jsch.getSession(this.sftpUser, this.sftpHost, 3232);
          session.setPassword(this.sftpPass);
          java.util.Properties config = new java.util.Properties();
          config.put("StrictHostKeyChecking", "no");
          session.setConfig(config);
          session.connect();
          channel = session.openChannel("sftp");
          channel.connect();
          channelSftp = (ChannelSftp) channel;
          channelSftp.cd(this.sftpWorkDir);
      }
  
      public SFTPConnection() throws JSchException, SftpException {
  
          sftpWorkDir = SFTPWORKINGDIRINC;
          JSch jsch = new JSch();
          session = jsch.getSession(SFTPUSER, SFTPHOST, 3232);
          session.setPassword(SFTPPASS);
          java.util.Properties config = new java.util.Properties();
          config.put("StrictHostKeyChecking", "no");
          session.setConfig(config);
          session.connect();
          channel = session.openChannel("sftp");
          channel.connect();
          channelSftp = (ChannelSftp) channel;
          channelSftp.cd(SFTPWORKINGDIRINC);
      }
  
      public static void main(String[] args) {
          try {
              SFTPConnection con=new SFTPConnection();
          } catch (JSchException e) {
              e.printStackTrace();
          } catch (SftpException e) {
              e.printStackTrace();
          }
      }
  }
  </code></pre>
  
  <p>This code works on my machine, but now I need to deploy it on another server with high security level. And this is what I've got.
  The exception is:</p>
  
  <pre><code>com.jcraft.jsch.JSchException: java.net.ConnectException: Connection timed out: connect
      at com.jcraft.jsch.Util.createSocket(Util.java:344)
      at com.jcraft.jsch.Session.connect(Session.java:215)
      at com.jcraft.jsch.Session.connect(Session.java:183)
      at SFTPConnection.&lt;init&gt;(SFTPConnection.java:53)
      at SFTPConnection.main(SFTPConnection.java:62)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:606)
      at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)
  Caused by: java.net.ConnectException: Connection timed out: connect
      at java.net.DualStackPlainSocketImpl.connect0(Native Method)
      at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:79)
      at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:339)
      at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:200)
      at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:182)
      at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:172)
      at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
      at java.net.Socket.connect(Socket.java:579)
      at java.net.Socket.connect(Socket.java:528)
      at java.net.Socket.&lt;init&gt;(Socket.java:425)
      at java.net.Socket.&lt;init&gt;(Socket.java:208)
      at com.jcraft.jsch.Util.createSocket(Util.java:338)
      ... 9 more
  </code></pre>
  
  <p>I was trying to connect using WinSCP with same parameters. I was trying to change port from <code>3232</code> to <code>22</code>, but still this error. What's wrong?</p>
  
  <p><strong>UPD:</strong>
  I can not ping <code>prod-sftp.host.ru</code>:</p>
  
  <pre><code>Pinging #ipaddress# with 32 bytes of data:
  Request timed out.
  Request timed out.
  Request timed out.
  Request timed out.
  </code></pre>
  
  <p>But telnet can connect to 22-nd port.</p>
  
  <p><strong>PS</strong></p>
  
  <p>Most parameters are not real. Don't try to ping it yourself. I just don't wanna share host, username and password with you. </p>