FTPClient - Java, upload file(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.
我正在使用以下类:
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();
}
为什么这不起作用,我该如何解决?
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,上传文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:FTPClient - Java,上传文件


- Eclipse 插件更新错误日志在哪里? 2022-01-01
- C++ 和 Java 进程之间的共享内存 2022-01-01
- Jersey REST 客户端:发布多部分数据 2022-01-01
- 从 finally 块返回时 Java 的奇怪行为 2022-01-01
- Safepoint+stats 日志,输出 JDK12 中没有 vmop 操作 2022-01-01
- 如何使用WebFilter实现授权头检查 2022-01-01
- Java包名称中单词分隔符的约定是什么? 2022-01-01
- value & 是什么意思?0xff 在 Java 中做什么? 2022-01-01
- 将log4j 1.2配置转换为log4j 2配置 2022-01-01
- Spring Boot连接到使用仲裁器运行的MongoDB副本集 2022-01-01