问题描述
我正在尝试将文件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.
这篇关于一旦FTP在java中完成,就会创建0 kb文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!