我正在尝试在java中实现ftp下载。我正在使用apache common-net library但是我得到了这个异常。我打印出下面的堆栈跟踪我不知道我错过了什么
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();
}
我的方法如下
Float64[]
请帮助我错过的东西。
答案 0 :(得分:5)
抱歉!因为我的愚蠢
//login to server
if (!ftpClient.login("username", "password")) {
ftpClient.logout();
}
这是错误,正在两次退出