与JSCH库的连接超时

我已经使用JSCH库实现了SFTP连接,但我一直在获得连接超时错误。我已经尝试增加超时价值,但似乎没有任何作用。但是,我可以使用Brower访问FTP网站。我的代码如下:

public class FileTransfer {
    public static void main(String[] args) {
        final String hostName = "filetransfer.company.com";
        final int port = 22;
        final String userName = "user_name";
        final String password = "password" ;
        JSch jsch = new JSch();
        String knowHosts = new StringBuilder().append(System.getProperty("user.home")).append("/.ssh/known_hosts").toString();
        System.out.println(knowHosts);
        try {
            jsch.setKnownHosts(knowHosts);
            Session session = jsch.getSession(userName, hostName, port);
            System.out.println("session created");
            session.setPassword(password);
            System.out.println("all properties set "+session.toString());
            session.setConfig("StrictHostKeyChecking", "no");
            //session.setSocketFactory(new SocketFactoryWithTimeout());
            session.connect(60000);
            System.out.println("session connected");
            Channel channel = session.openChannel("sftp");
            channel.connect();
            System.out.println("channel created and connected");
            ChannelSftp channelSftp = (ChannelSftp) channel;
            channelSftp.get("sample_file.csv", "src/main/resources/downloaded_file.csv");
            channelSftp.exit();
            System.out.println("file download and saved in resource directory");
        } catch (JSchException | SftpException e) {
            e.printStackTrace();
        }
    }
}

我遇到的错误是:

session created
all properties set com.jcraft.jsch.Session@30f39991
com.jcraft.jsch.JSchException: java.net.ConnectException: Connection timed out: connect
    at com.jcraft.jsch.Util.createSocket(Util.java:394)
    at com.jcraft.jsch.Session.connect(Session.java:215)
    at com.wf.se.ftp.FileTransfer.main(FileTransfer.java:22)
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:350)
    at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
    at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
    at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:172)
    at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
    at java.net.Socket.connect(Socket.java:606)
    at java.net.Socket.connect(Socket.java:555)
    at java.net.Socket.<init>(Socket.java:451)
    at java.net.Socket.<init>(Socket.java:228)
    at com.jcraft.jsch.Util$1.run(Util.java:362)
    at java.lang.Thread.run(Thread.java:748)

任何建议都会有所帮助。谢谢你。

stack overflow Connection timeout with Jsch library
原文答案