JSch套接字超时-连接超时 [英] JSch Socket timeout - Connection timeout

查看:358
本文介绍了JSch套接字超时-连接超时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用JSch建立SFTP会话.该代码正常工作,并且我可以与多个服务器建立会话.但是,今天我遇到了其中一台服务器的问题.

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:?]

调试后,我发现该问题发生在Session.class中.

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会话超时限制

谢谢

推荐答案

对于遇到上述问题的任何人,可能的原因之一可能是代理. JSch Session类在超时代码失败,但没有给出详细的堆栈跟踪.

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.

我必须启用代理才能克服此问题. session.setProxy(新的ProxyHTTP(PROXY_HOST,PROXY_PORT)).如果proxytype是那些各自的类型,则可能需要实现SOCKS4和SOCKS5代理.

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.

这篇关于JSch套接字超时-连接超时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆