因为工作需要实现FTP客户端。所以就在网上看了下别人的。自己在这记录下。
要实现FTP客户端需要下载2个JAR。jakarta-oro-2.0.8.jar,和commons-net-1.4.1.jar
public static void main(String[] args) throws Exception {
FTPClient ftp = new FTPClient();
ftp.setControlEncoding("utf-8");
FTPClientConfig conf = new FTPClientConfig(FTPClientConfig.SYST_NT);
conf.setServerLanguageCode("zh");
ftp.connect("10.1.1.249", 21);
Boolean b=ftp.login("xiaopeng", "xiaopeng");
int reply=ftp.getReplyCode();
if(!FTPReply.isPositiveCompletion(reply)){
}else{
System.out.println("登录成功");
ftp.changeWorkingDirectory("leadbank"+File.separator);
FTPFile f[]=ftp.listFiles();
for(FTPFile ff:f){
System.out.println(ff.getName());
if(ff.getName().equals("Readme.txt")){
File fi = new File("d:"+File.separator+"Readme.txt");
if(!fi.exists()){
}else{
fi.createNewFile();
}
OutputStream o = new FileOutputStream(fi);
BufferedOutputStream buffer = new BufferedOutputStream(o);
ftp.retrieveFile("Readme.txt",buffer);
buffer.flush();
buffer.close();
o.close();
ftp.logout();
System.out.println("下载完成退出");
}
}
}
}
mark一下