码迷,mamicode.com
首页 > 编程语言 > 详细

java ftp

时间:2018-06-26 12:23:05      阅读:163      评论:0      收藏:0      [点我收藏+]

标签:ftpclient   依赖   user   rect   java   mode   put   log   ftp   

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));

java ftp

标签:ftpclient   依赖   user   rect   java   mode   put   log   ftp   

原文地址:https://www.cnblogs.com/blog-ice/p/9228300.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!