gpt4 book ai didi

java - 使用 Apache Common Net 从 FTP 下载到设备的损坏的 PDF 文件

转载 作者:行者123 更新时间:2023-11-30 10:20:21 25 4
gpt4 key购买 nike

我正在尝试将文件从 FileZilla 服务器下载到 Android 设备。一切似乎都是正确的,与 FTP 的连接、登录、文件存在并且下载响应正常。但是当我转到 Android 设备中的文件时,它只有 64KB 的大小,它一定是并且由于已损坏我无法打开......我尝试了另一个 49KB 的文件并下载了 48KB 并且它是也腐败了。我使用 Adob​​e Acrobat Reader 和 QuickOffice 打开文件。

String usuarioLogin = params[0];

FTPClient ftp = null;
String LOG_TAG = "FTP";
ftp = new FTPClient();
String server = params[0];
int portNumber = Integer.parseInt(params[1]);
String user = params[2];
String password = params[3];
String filename = params[4];
File localFile = UtilsVictor.crearFichero(params[5]);

ftp.connect(server, portNumber);
Log.d(LOG_TAG, "Connected. Reply: " + ftp.getReplyString());
ftp.enterLocalPassiveMode();

ftp.login(user, password);
Log.d(LOG_TAG, "Logged in");
ftp.setFileType(FTP.LOCAL_FILE_TYPE);
Log.d(LOG_TAG, "Downloading");

OutputStream outputStream = null;
boolean success = false;
outputStream = new BufferedOutputStream(new FileOutputStream(
localFile));
success = ftp.retrieveFile(filename, outputStream);

if(success) {
Log.d(LOG_TAG, "success!!");
} else{
Log.d(LOG_TAG, "NOOOOT success!!");
}

FileZilla 服务器的日志:

(000019)13/01/2018 17:13:14 - (not logged in) (192.168.1.38)> Connected on port 50000, sending welcome message...
(000019)13/01/2018 17:13:14 - (not logged in) (192.168.1.38)> 220-FileZilla Server 0.9.60 beta
(000019)13/01/2018 17:13:14 - (not logged in) (192.168.1.38)> 220-written by Tim Kosse (tim.kosse@filezilla-project.org)
(000019)13/01/2018 17:13:14 - (not logged in) (192.168.1.38)> 220 Please visit https://filezilla-project.org/
(000019)13/01/2018 17:13:14 - (not logged in) (192.168.1.38)> USER VICTOR
(000019)13/01/2018 17:13:14 - (not logged in) (192.168.1.38)> 331 Password required for victor
(000019)13/01/2018 17:13:14 - (not logged in) (192.168.1.38)> PASS ****
(000019)13/01/2018 17:13:14 - victor (192.168.1.38)> 230 Logged on
(000019)13/01/2018 17:13:14 - victor (192.168.1.38)> TYPE I
(000019)13/01/2018 17:13:14 - victor (192.168.1.38)> 200 Type set to I
(000019)13/01/2018 17:13:14 - victor (192.168.1.38)> PASV
(000019)13/01/2018 17:13:14 - victor (192.168.1.38)> 227 Entering Passive Mode (192,168,1,41,125,49)
(000019)13/01/2018 17:13:14 - victor (192.168.1.38)> RETR /Informes/572760344M/aaa.pdf
(000019)13/01/2018 17:13:14 - victor (192.168.1.38)> 150 Opening data channel for file download from server of "/Informes/572760344M/aaa.pdf"
(000019)13/01/2018 17:13:14 - victor (192.168.1.38)> 226 Successfully transferred "/Informes/572760344M/aaa.pdf"
(000019)13/01/2018 17:13:48 - victor (192.168.1.38)> disconnected.

问题出在哪里??

最佳答案

你不见了

outputStream.close();

无需完全重写您的代码。你的new code只是不必要地重新实现,什么FTPClient.retrieveFile在内部做。

即使您选择使用 FTPClient.retrieveFileStream , 使用 Util.copyStream ) 而不是自己实现复制循环。

关于java - 使用 Apache Common Net 从 FTP 下载到设备的损坏的 PDF 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48241499/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com