/*
I run a FTP server on localhost.when I download files use ftpClient.retrieveFile() method,it's replyCode is 550 . I read the API of commons-net and find the 550 replyCode,the defines is" public static final int FILE_UNAVAILABLE 550".but I cannot find the problem from my codes.
thanks for your help.
*/
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);
}
}