我的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