JSch Socket timeout - Connection timeout

孤者浪人 提交于 2019-12-08 15:07:11

问题


I am trying to establish an SFTP session using JSch. The code is working correctly and I am able to establish a session with multiple servers. However, today I am encountering an issue with one of the server.

Caused by: com.jcraft.jsch.JSchException: java.net.ConnectException: Connection timed out: 
connect at com.jcraft.jsch.Util.createSocket(Util.java:349) ~[jsch-0.1.54.jar:?]
        at com.jcraft.jsch.Session.connect(Session.java:215) ~[jsch-0.1.54.jar:?]
        at com.jcraft.jsch.Session.connect(Session.java:183) ~[jsch-0.1.54.jar:?]

After debugging, I see that the issue is happening in Session.class.

tmp.join(timeout);

I tried explicitly setting up the timeout like below but it's still failing:

JSch jsch = new JSch();
Session session = jsch.getSession(userName, ip, port);
session.setPassword(password);
session.setConfig("StrictHostKeyChecking", "no");
session.connect(60000);

Note: Without passing these timeouts also, I never got into an issue so far.

Can someone help me in understanding the possible cause for this behavior and guide me regarding timeouts? Also, why will the below solution help if it will? I am trying to understand the root cause and resolution for the same.

JSch session timeout limit

Thanks


回答1:


For anyone getting an issue like the one mentioned above, one of the probable cause could be proxy. The JSch Session class was failing at a timeout code without giving detailed stack trace.

I had to enable the proxy in order to get past this issue. session.setProxy(new ProxyHTTP(PROXY_HOST, PROXY_PORT)). I may need to implement SOCKS4 and SOCKS5 proxy if the proxytype is of those respective types.



来源:https://stackoverflow.com/questions/53164471/jsch-socket-timeout-connection-timeout

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!