如何下载从FTP服务器上的文件到Android设备? [英] How to download a file from FTP server to Android device?
本文介绍了如何下载从FTP服务器上的文件到Android设备?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个要求的从FTP服务器上的图像下载到Android设备的。我用试过几样 ftp4j-1.7.2.jar
库,但是未能与FTP服务器连接&放大器;搞砸了。
I have a requirement to download a image from FTP server to android device. I tried with few samples by using ftp4j-1.7.2.jar
library, but failed to connect with FTP servers & messed up.
与FTP服务器的任何人合作?
Have anyone worked with FTP servers?
请建议建立连接和放大器;从服务器下载文件。
Please suggest to make connection & download file from Server.
推荐答案
检查低于code,从FTP服务器上下载文件:
Check below code to download file from FTP server:
private Boolean downloadAndSaveFile(String server, int portNumber,
String user, String password, String filename, File localFile)
throws IOException {
FTPClient ftp = null;
try {
ftp = new FTPClient();
ftp.connect(server, portNumber);
Log.d(LOG_TAG, "Connected. Reply: " + ftp.getReplyString());
ftp.login(user, password);
Log.d(LOG_TAG, "Logged in");
ftp.setFileType(FTP.BINARY_FILE_TYPE);
Log.d(LOG_TAG, "Downloading");
ftp.enterLocalPassiveMode();
OutputStream outputStream = null;
boolean success = false;
try {
outputStream = new BufferedOutputStream(new FileOutputStream(
localFile));
success = ftp.retrieveFile(filename, outputStream);
} finally {
if (outputStream != null) {
outputStream.close();
}
}
return success;
} finally {
if (ftp != null) {
ftp.logout();
ftp.disconnect();
}
}
}
这篇关于如何下载从FTP服务器上的文件到Android设备?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文