我正在 Android 上开发一个连接到 FTP 服务器以上传和下载文件的应用程序。为了建立连接,我正在使用基于此的 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;
}