[英]Apache commons-net FTP Error
I am trying to implement ftp download in java. 我正在尝试在Java中实现ftp下载。 I am using apache common-net library but I am getting this exception.I have the below stack trace printed out I not sure what am I missing
我正在使用apache common-net库,但遇到此异常。我打印出以下堆栈跟踪信息,我不确定丢失了什么
org.apache.commons.net.ftp.FTPConnectionClosedException: Connection closed without indication.
at org.apache.commons.net.ftp.FTP.__getReply(FTP.java:317)
at org.apache.commons.net.ftp.FTP.__getReply(FTP.java:294)
at org.apache.commons.net.ftp.FTP.sendCommand(FTP.java:483)
at org.apache.commons.net.ftp.FTP.sendCommand(FTP.java:608)
at org.apache.commons.net.ftp.FTP.sendCommand(FTP.java:582)
at org.apache.commons.net.ftp.FTP.pasv(FTP.java:1007)
at org.apache.commons.net.ftp.FTPClient._openDataConnection_(FTPClient.java:869)
at org.apache.commons.net.ftp.FTPClient._retrieveFile(FTPClient.java:1854)
at org.apache.commons.net.ftp.FTPClient.retrieveFile(FTPClient.java:1845)
I have a the method as follows 我有如下方法
public void downloadFromFtp(Map<String, String> ftpMap, String sourceWithPath,
String destinationFolder) throws IOException {
String hostname = ftpMap.get("hostname");
String username = ftpMap.get("username");
String password = ftpMap.get("password");
if (null == hostname || null == username || null == password) {
throw new InvalidInputException(
"Invalid RMS FTP hostname/username/password");
}
//Connect to ftp url
ftpClient.connect(hostname, 21);
ftpClient.setFileType(FTP.BINARY_FILE_TYPE);
//login to server
if (!ftpClient.login("username", "password")) {
ftpClient.logout();
}
int reply = ftpClient.getReplyCode();
//FTPReply stores a set of constants for FTP reply codes.
if (!FTPReply.isPositiveCompletion(reply)) {
ftpClient.disconnect();
}
//enter passive mode
ftpClient.enterLocalPassiveMode();
File tempFile = new File(sourceWithPath);
OutputStream output =
new BufferedOutputStream(new FileOutputStream(destinationFolder + "/" + tempFile.getName()));
ftpClient.retrieveFile(sourceWithPath, output);
output.close();
ftpClient.logout();
ftpClient.disconnect();
}
Please Help what Iam I missing. 请帮助我失踪的我。
Sorry! 抱歉! for my stupidity
为了我的愚蠢
//login to server
if (!ftpClient.login("username", "password")) {
ftpClient.logout();
}
Here is the mistake, was doing logout twice 这是错误,两次注销
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.