我通过提供 URL 成功将单个文件从 FTP 服务器下载到我的 SD 卡。但我无法从 FTP 服务器下载包含 30 个文件(.jpg、.flv 等,文件夹内可能有另一个文件夹)的文件夹.所以请帮我一些代码,如何将整个文件夹从 FTP 服务器下载到 SD 卡。提前致谢!!
这是单个文件下载的代码:
public boolean downloadFTP(String srcFilePath, String desFilePath) {
boolean status = false;
FTPClient client = new FTPClient();
try {
String ipaddr = "XX.XX.XX.XX";
String uname = "XXXXXX";
String pass = "XXXXXX";
client.connect(ipaddr, 21);
client.enterLocalPassiveMode();
boolean login = client.login(uname, pass);
if (login) {
Log.e("downloadFTP login : ", "Success");
FileOutputStream desFileStream = new FileOutputStream(
desFilePath);
Log.e("downloadFTP login : ", "FileOutputStream");
status = client.retrieveFile(srcFilePath, desFileStream);
Log.e("downloadFTP status : ", "" + status);
desFileStream.close();
}
} catch (Exception e) {
Log.e("ERROR downloadFTP : ", e.getMessage());
} finally {
try {
client.disconnect();
} catch (IOException e) {
e.printStackTrace();
}
}
return status;
}