gpt4 book ai didi

java - Android 如何连接到 FTP?

转载 作者:搜寻专家 更新时间:2023-11-01 09:10:12 25 4
gpt4 key购买 nike

我正在尝试通过 apache FTP 连接到服务器:

public boolean ftpConnect(String host, String user, String pass){
try {
ftpClient = new FTPClient();
ftpClient.connect(host);
if(FTPReply.isPositiveCompletion(ftpClient.getReplyCode())){
boolean status = ftpClient.login(user, pass);
ftpClient.enterLocalPassiveMode();
return status;
}
} catch (SocketException e) {
Log.d("FTP", "Error: could not connect to socket " + host );
} catch (IOException e) {
Log.d("FTP", "Error: could not connect to host " + host );
}
return false;
}

如果我通过 WI-FI 连接到互联网,上面的代码可以工作,但是如果我通过 3G 连接则不能工作。我已经在显现。我还没有在谷歌上找到对此的解释。

最佳答案

try {
FTPClient ftpClient = new FTPClient();
ftpClient.connect(InetAddress.getByName(Your host Url));
ftpClient.login(loginName, password);
System.out.println("status :: " + ftpClient.getStatus());
} catch (Exception e) {
e.printStackTrace();
}

此外,请在此处查看我的回答:Track FTP upload data in android? .

关于java - Android 如何连接到 FTP?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8760984/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com