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的文件中;

    }

}
//结束后关闭ftp   避免资源浪费ftp.logOut();





 

 

 

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值