由网友(永不落的梦想)分享简介:我有一个要求的从FTP服务器上的图像下载到Android设备的。我用试过几样 ftp4j-1.7.2.jar 库,但是未能与FTP服务器连接&放大器;搞砸了。I have a requirement to download a image from FTP server to android device. I...
我有一个要求的从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();
}
}
}
相关推荐
最新文章