本文介紹了使用 Apache Commons Net 下載后 FTP 文件損壞的處理方法,對(duì)大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)吧!
問題描述
由此下載的文件,大小幾乎相同,但某些行不同.每個(gè)答案都指向二進(jìn)制文件類型.但這無(wú)濟(jì)于事.有人知道這個(gè)問題(傳輸 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();
}
推薦答案
使用包含空格的非轉(zhuǎn)義路徑時(shí)似乎會(huì)發(fā)生這種情況.例如.C:/Documents and Settings/測(cè)試
It seems to happen when using unescaped paths that contain spaces. E.g. C:/Documents and Settings/test
現(xiàn)在通過對(duì)空格使用轉(zhuǎn)義路徑解決了這個(gè)問題.感謝您的幫助
Got it solved now by using a escaped path for the spaces. Thanks for your help
這篇關(guān)于使用 Apache Commons Net 下載后 FTP 文件損壞的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!
【網(wǎng)站聲明】本站部分內(nèi)容來(lái)源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請(qǐng)聯(lián)系我們刪除處理,感謝您的支持!