我的java程序從我的系統上傳一個zip文件到FTP服務器。 uploadfile()
是一個包含上傳代碼的函數。Zip文件上傳到服務器時被破壞
uploadfile( 「192.168.0.210」, 「muruganp」, 「vm4snk」, 「/首頁/管理/ GATE521/LN_RB_Semivalid2junk /輸出/」 +日期+ 「_ RB1.zip」,「/文件服務器/ filesbackup/EMAC /"+date+"_RB1.zip「);
public static boolean uploadfile(String server, String username,
String Password, String source_file_path, String dest_dir) {
FTPClient ftp = new FTPClient();
try {
int reply;
ftp.connect(server);
ftp.login(username, Password);
System.out.println("Connected to " + server + ".");
System.out.print(ftp.getReplyString());
reply = ftp.getReplyCode();
if (!FTPReply.isPositiveCompletion(reply)) {
ftp.disconnect();
System.err.println("FTP server refused connection.");
return false;
}
System.out.println("FTP server connected.");
InputStream input = new FileInputStream(source_file_path);
ftp.storeFile(dest_dir, input);
System.out.println(ftp.getReplyString());
input.close();
ftp.logout();
} catch (Exception e) {
System.out.println("err");
e.printStackTrace();
return false;
} finally {
if (ftp.isConnected()) {
try {
ftp.disconnect();
} catch (Exception ioe) {}
}
}
return true;
}
,我就在我的系統中的zip文件是完美的。但是,在服務器位置上傳相同的內容之後,下載相同的內容並解決問題。 「該文件已損壞」說錯誤。我該怎麼做才能解決這個問題。請告知這一點。
我懷疑問題是類似的,通過ASCII模式傳輸。它實際上應該按照這個QUESTION通過二進制模式傳輸。如何達到相同?請指教。
如何更改爲二進制模式?在java中是一個初學者..請解釋 – LGAP 2010-10-20 23:15:56
@LAPP - 你必須展示更多的代碼,你用什麼API來做FTP? – 2010-10-20 23:20:11
當然..我已經更新了我的問題老闆。 – LGAP 2010-10-20 23:21:09