0 kb file created once FTP is done in java(在 java 中完成 FTP 后创建 0 kb 文件)
问题描述
我正在尝试将文件通过 FTP 传输到远程计算机上.下面是我的代码:-
I am trying to FTP a file on to a remote machine. Below is my code :-
FTPClient ftpClient = new FTPClient();
ftpClient.connect("home.abc.com");
ftpClient.login("remote", "guesst12");
int replyCode = ftpClient.getReplyCode();
ftpClient.changeWorkingDirectory("share"))
ftpClient.setFileType(FTPClient.BINARY_FILE_TYPE);
InputStream input = new FileInputStream(new File("H:/testFile.txt"));
OutputStream out = ftpClient.storeFileStream("testFile.txt");
Util.copyStream(input, out);
out.close();
input.close();
ftpClient.completePendingCommand()
ftpClient.logout();
ftpClient.disconnect();
当我执行这段代码时,代码执行没有任何问题,但是在远程机器上,当我检查文件时,正在创建文件,但没有内容 (OKB) 文件.我在代码中遗漏了什么吗?
When i execute this piece of code, the code is executed without any issues, but at the remote machine, when i check the file, the file is being created, but with no content (OKB) file. Am i missing something in code.
[更新]:我尝试使用以下代码存储文件:-
[Update] : I tried with the following code for storing file :-
if(ftpClient.storeFile("testCopy.txt", input)) {
System.out.println("File Stored Successfully");
}
System.out.println(ftpClient.getReplyString());
现在我收到的回复代码是:- 451 写入本地文件失败.
这是什么意思.
Now the reply code i recieved is :- 451 Failure writing to local file.
What does that means.
谢谢
推荐答案
看了一遍又一遍后,我不断想出不同的东西.
After looking at it over and over I keep coming up with different things.
您确定 InputStream 在您复制流之前正在读取文件吗?因为我不确定 FileInputStream 读取的是启动时的文件.
Are you sure that the InputStream is reading the file before your copying the stream? Because I'm not sure FileInputStream read's the file on initiation.
这篇关于在 java 中完成 FTP 后创建 0 kb 文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:在 java 中完成 FTP 后创建 0 kb 文件


基础教程推荐
- 如何在 JFrame 中覆盖 windowsClosing 事件 2022-01-01
- 从 python 访问 JVM 2022-01-01
- 如何在 Spring @Value 注解中正确指定默认值? 2022-01-01
- 验证是否调用了所有 getter 方法 2022-01-01
- 多个组件的复杂布局 2022-01-01
- Java Swing计时器未清除 2022-01-01
- Java 实例变量在两个语句中声明和初始化 2022-01-01
- 不推荐使用 Api 注释的描述 2022-01-01
- 大摇大摆的枚举 2022-01-01
- 在 Java 中创建日期的正确方法是什么? 2022-01-01