本文介紹了使用 Apache Commons Net 下載后 FTP 文件損壞的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
由此下載的文件,大小幾乎相同,但某些行不同.每個答案都指向二進制文件類型.但這無濟于事.有人知道這個問題(傳輸 PDF)嗎?
The files downloaded by this, are nearly the same size but differ in some lines. Every answer points to binary file type. But this won't help. Got anybody an idea for the problem (transferring PDF)?
FTPClient ftpClient = new FTPClient();
OutputStream outputStream = null;
boolean resultOk = true;
try {
ftpClient.connect(host, port);
ftpClient.enterLocalPassiveMode();
ftpClient.setFileTransferMode(FTP.COMPRESSED_TRANSFER_MODE);
ftpClient.setFileType(FTP.BINARY_FILE_TYPE);
if (showMessages) {
System.out.println(ftpClient.getReplyString());
}
resultOk &= ftpClient.login(usr, pwd);
if (showMessages) {
System.out.println(ftpClient.getReplyString());
}
outputStream = new FileOutputStream(localResultFile);
resultOk &= ftpClient.retrieveFile(remoteSourceFile, outputStream);
outputStream.flush();
outputStream.close();
if (showMessages) {
System.out.println(ftpClient.getReplyString());
}
if (resultOk == true) {
resultOk &= ftpClient.deleteFile(remoteSourceFile);
}
resultOk &= ftpClient.logout();
if (showMessages) {
System.out.println(ftpClient.getReplyString());
}
} finally {
ftpClient.disconnect();
}
推薦答案
使用包含空格的非轉義路徑時似乎會發生這種情況.例如.C:/Documents and Settings/測試
It seems to happen when using unescaped paths that contain spaces. E.g. C:/Documents and Settings/test
現在通過對空格使用轉義路徑解決了這個問題.感謝您的幫助
Got it solved now by using a escaped path for the spaces. Thanks for your help
這篇關于使用 Apache Commons Net 下載后 FTP 文件損壞的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!