java ftp 长连接超时,连接失败:ETIMEDOUT(连接超时)以ftp连接

在Android应用中使用FTP上传图片时,遇到从WiFi切换到3G或2G网络时连接超时的问题。通过设置FTP客户端的连接超时时间可以解决这个问题。原始代码在部分网络环境下导致`java.net.ConnectException: failed to connect to Host (port 21): connect failed: ETIMEDOUT (Connection timed out)`错误。解决方案是增加FTP客户端的连接超时时间,例如设置为50秒,以适应慢速网络连接。
摘要由CSDN通过智能技术生成

I have been using ftp to upload images on server in android application and I'm using the following code to connect with ftp. it's working fine in Wi-fi but if I switched to 3G or 2G connection, I am getting connection time out error. So would you please let me know how to take care of this situation. And my client is also facing this issue in Veriozon, Sprint, ATT network provider too. It's iPhone version is working fine in all network.

Code :

try {

ftpClient = new FTPClient();

ftpClient.setConnectTimeout(30);

ftpClient.connect(InetAddress.getByName(server));

boolean isLogin = ftpClient.login(username, password);

boolean workingDir = ftpClient

.changeWorkingDirectory(path);

if (ftpClient.getReplyString().contains("250")) {

ftpClient

.setFileType(org.apache.comm

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值