FTPClient - Java,上传文件 [英] FTPClient - Java, upload file

查看:165
本文介绍了FTPClient - Java,上传文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试做一个非常简单的文件上传。我想要一个可以上传我告诉它的任何文件的Java FTPClient。但PDF总是搞砸了,我的PDF编辑器(Adobe)不会打开它,说有一个I / O错误。

I'm trying to do a VERY simple file upload. I want a Java FTPClient that can upload any file I tell it to. But the pdf always gets all messed up and my pdf editor (Adobe) won't open it, saying there is an I/O error.

我正在使用以下课程:

I'm using the following class:

    import org.apache.commons.net.ftp.FTPClient;
    ....

    FTPClient client = new FTPClient();
    FileInputStream fis = null;

    try {
        client.connect("mydomain.com");
        client.login("user", "password");

        String filename = "myPDF.pdf";
        fis = new FileInputStream(filename);

        client.storeFile("temp.pdf", fis);
        fis.close();
        client.logout();
    } catch (IOException e) {
        e.printStackTrace();
    }

为什么不行,我该如何解决? p>

Why doesn't this work, and how do I fix it?

推荐答案

它不起作用,因为FTPClient FTP.ASCII_FILE_TYPE 。您只需更新配置即可以二进制模式传输。

It doesn't work because the default transfer mode for FTPClient is FTP.ASCII_FILE_TYPE. You just need to update the configuration to transfer in binary mode.

这篇关于FTPClient - Java,上传文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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