Java FTPClient正在返回:无法分析响应代码
当我尝试使用FTPClient检索文件时,我收到此消息:Java FTPClient正在返回:无法分析响应代码,java,ftp,apache-commons,Java,Ftp,Apache Commons,当我尝试使用FTPClient检索文件时,我收到此消息: Could not parse response code. Server Reply: 150 Opening data channel for file download from server 我如何连接: FTPClient ftpClient = new FTPClient(); ftpClient.setDefaultTimeout(this.timeout); try { ftpC
Could not parse response code.
Server Reply:
150 Opening data channel for file download from server
我如何连接:
FTPClient ftpClient = new FTPClient();
ftpClient.setDefaultTimeout(this.timeout);
try {
ftpClient.connect(this.host, this.port);
ftpClient.setSoTimeout(this.timeout);
if (!ftpClient.login(username, password)) {
return null;
}
} catch (IOException e) {
return null;
}
导致问题的代码是:
File downloadedFile = new File(localFile);
try (OutputStream outputStream = new BufferedOutputStream(new FileOutputStream(downloadedFile))) {
ftpClient.retrieveFile(remoteFilePath, outputStream);
}
当我通过FTP命令手动下载文件时,会收到多行回复:
ftp> get file
local: file remote: file
200 Port command successful
150 Opening data channel for file download from server of "/file"
226 Successfully transferred "/file"
202 bytes received in 0.00 secs (1777.2 kB/s)
可能是传输完成前连接已关闭,或者传输方法无效
- 您是否可以尝试通过Filezilla客户端下载该文件以测试它是否工作
- 你能分享你用来连接FTP的代码吗
import org.apache.commons.net.ftp.ftp;
try(OutputStream OutputStream=new BufferedOutputStream(new FileOutputStream(downloaddedfile))){
//这些行将文件类型设置为二进制。
//我有一些问题,下载的文件已损坏。
ftpClient.setFileTransferMode(FTP.BINARY文件类型);
ftpClient.setFileStructure(FTP.FILE_结构);
ftpClient.setFileType(FTP.BINARY文件类型);
ftpClient.setConnectTimeout(超时);
ftpClient.retrieveFile(remoteFilePath,outputStream);
}
此外,还检查了超时值。向我们显示超时值。