欢迎访问『www.cnblogs.com/blog-ice』

1.添加依赖

  commons-net-3.6.jar

2.获取ftp客户端

  ftpClient = new FTPClient();

  ftpClient.connect(ip, port);

  ftpClient.login(username, password);

  ftpClient.setBufferSize(8096);

  ftpClient.changeWorkingDirectory("/root");

  ftpClient.setFileType(FTPClient.BINARY_FILE_TYPE);

  ftpClient.enterLocalPassiveMode();

3.下载

  remote = new String((ftpClient.printWorkingDirectory() + filepath).getBytes("gbk"), "ISO885901");

  file = new File(local);

  ftpClient.retrieveFile(remote, new FileOutputStream(file));

4.上传

  remote = new String((ftpClient.printWorkingDirectory() + filepath).getBytes("gbk"), "ISO885901");

  file = new File(local);

  ctpClient.makeDirectory((ftpClient.printWorkingDirectory() + filepath).getBytes("gbk"), "ISO885901");

  ftpClient.storeFile(remote, new FileOutputStream(file));

posted on 2018-06-26 11:34  仙路尽头谁为峰  阅读(245)  评论(0编辑  收藏  举报
这里是自由发挥的天堂