问题
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