/* 我在 localhost 上运行 FTP 服务器。当我下载文件时使用 ftpClient.retrieveFile() 方法,它的 replyCode 是 550 。我阅读了 commons-net 的 API 并找到了 550 回复代码,定义为“public static final int FILE_UNAVAILABLE 550”。但我无法从我的代码中找到问题。
谢谢你的帮助。
*/
FTPClient ftpClient = new FTPClient();
FileOutputStream fos = null;
try {
ftpClient.connect("192.168.1.102",2121);
ftpClient.login("myusername", "12345678");
ftpClient.setControlEncoding("UTF-8");
ftpClient.setFileType(FTPClient.BINARY_FILE_TYPE);
String remoteFileName = "ftpserver.zip";//this file in the rootdir
fos = new FileOutputStream("f:/down.zip");
ftpClient.setBufferSize(1024);
ftpClient.enterLocalPassiveMode();
ftpClient.enterLocalActiveMode();
ftpClient.retrieveFile(remoteFileName, fos);
System.out.println("retrieveFile?"+ftpClient.getReplyCode());
fos.close();
ftpClient.logout();
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
ftpClient.disconnect();
} catch (IOException e) {
e.printStackTrace();
throw new RuntimeException("关闭FTP异常", e);
}
}