ftp “/”目录下文件获取

 
 
 
 
 
 
 
 
 
 
使用jar包comment-net-3.3.jar
public class FtphandlerImpl{

private FTPClient  ftp;
public FTPClient getFTPClient(String serverIp, String userName, String password, String port){

    ftp=new FTPClient ();
    ftp.connect(serverIp,port)

    syso(ftp.logein(userName,password)+"如果为true则登陆成功");

    retur ftp;

}
public static void main(String []args) throws IOException{
FtphandlerImpl ftpImpl=new FtphandlerImpl("00.10.01.123","hello","hello",21)
    FTPFile files=FTPClient .listFiles("/");//获取“/”目录下的文件组
    FTPClient ft=ftpimpl.getFTPClient("url",user,pass,port);
    ft.setControlEncoding("UTF-8");
    ft.enterLocalPassiveMode();//加被动模式可以提高连接效率和处理速度
    File localFile=new File("d:"+File.separator+fileName);//创建本地文件用于接收流;
    OutputStream out =FileOutputStream(localFile);
    FTPFile []fileList=ft.listFiles("/");
    for(int i=0;i<fileList.length;i++){
    syso(fileList[i].getName)
    }
    ft.retrieveFile(fileList[i].getName,out);//将fileList[i].getName中内容写到名为fileName的文件中;

    }

}








猜你喜欢

转载自blog.csdn.net/qq_37511875/article/details/80461710