上传到服务器时Zip文件被破坏 [英] Zip file getting corrupted when uploaded to server

查看:756
本文介绍了上传到服务器时Zip文件被破坏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的java程序从我的系统上传一个zip文件到FTP服务器。 uploadfile()是一个包含上传代码的函数。
$ b

My java program uploads a zip file from my system to FTP server. uploadfile() is a function that contains the uploading code.


uploadfile( 192.168.0.210\" , muruganp, vm4snk, /首页/管理/ GATE521 / LN_RB_Semivalid2junk /输出/ +日期+ _ RB1.zip, /文件服务器/ filesbackup / EMAC / +日期+ _ RB1.zip );

uploadfile("192.168.0.210","muruganp","vm4snk","/home/Admin/GATE521/LN_RB_Semivalid2junk/Output/"+date+"_RB1.zip","/fileserver/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文件非常完美。但是,在服务器位置上传相同的内容之后,下载相同的内容并解决问题。 该文件已损坏说错误。我该怎么做才能解决这个问题。请注意这一点。

The zip file that I do have in my system is perfect. But after uploading the same in the server location,downloading the same, and extracting the problem occurs. "The file is corrupt" says the error. What should I do to resolve this issue. Kindly advise on this.

我怀疑问题会出现,就像通过ASCII模式传输一样。它应该实际上按照这个问题通过二进制模式进行传输。如何达到相同?请大家指教。

I suspect the problem would be something like, transferring through ASCII mode. It should actually be transferred through binary mode as per this QUESTION. How to attain the same? Please advise.

推荐答案

最佳猜测是FTP上传使用ascii模式,这会破坏一个zip文件等二进制文件。验证这一点,如果是这样,改为二进制模式。

Best guess is that the FTP upload is using ascii mode which will corrupt a binary file like a zip. Verify this and if so change it to binary mode instead.

这篇关于上传到服务器时Zip文件被破坏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆