问题描述
我正在尝试将文件通过 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 文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!