java sftp 连接超时,JSch套接字超时-连接超时

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.

Thanks

解决方案

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.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值