【发布时间】:2012-07-05 10:25:49
【问题描述】:
我正在 Android 上开发一个连接到 FTP 服务器以上传和下载文件的应用程序。为了建立连接,我正在使用基于 this 的 apache commons-net 库的 FTPClient 类,并且我正在使用 Eclipse。
但我在我的 Logcat 上收到以下消息:
07-04 21:11:44.196: D/USB Virtual(14708): Error: could not connect to host ftp://xxx.xxx
以下是我的清单权限:
<uses-sdk android:minSdkVersion="7" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.INTERNET"/>
我真的很困惑为什么我无法连接到我的 FTP 服务器,在控制台中没有显示任何错误。我错过了什么吗?我会感谢任何帮助。
我正在添加用于连接到我的 FTP 服务器的代码:
public boolean ftpConnect(String host, String username, String password,
int port) {
try {
mFTPClient = new FTPClient();
//host is ftp://looner-project.zxq.net
mFTPClient.connect(host);
mFTPClient.connect(InetAddress.getByName(host));
if (FTPReply.isPositiveCompletion(mFTPClient.getReplyCode())) {
boolean status = mFTPClient.login(username, password);
mFTPClient.setFileType(FTP.BINARY_FILE_TYPE);
mFTPClient.enterLocalPassiveMode();
return status;
}
} catch (Exception e) {
Log.d(TAG, "Error: could not connect to host " + host);
}
return false;
}
【问题讨论】:
-
您的设备连接到互联网了吗?
-
我的设备已连接到互联网,问题是每当我的应用程序尝试连接到 FTP 服务器时,我都会收到消息
Error: could not connect to host ftp://xxx.xxx -
删除“ftp://”后尝试:mFTPClient.connect("xxx.xxx.xxx.xxx", port_num);
标签: java android mobile ftp-client