欢迎来到天天文库
浏览记录
ID:40553145
大小:33.74 KB
页数:12页
时间:2019-08-04
《FTP工具类(ftp4j)》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、FTP工具类(ftp4j)分类: Java2010-12-3117:50 209人阅读 评论(0) 收藏 举报 viewplain1.package com.lyis.commons.util; 2.import it.sauronsoftware.ftp4j.FTPClient; 3.import it.sauronsoftware.ftp4j.FTPException; 4.import it.sauronsoftware.ftp4j.FTPFile; 5.import java.io.File
2、; 6.import java.net.URL; 7.import java.util.Arrays; 8.import java.util.Comparator; 9.import org.apache.log4j.Logger; 10./** 11. * FTP文件处理工具类 12. * 13. * @author Johnson 14. * @version Tuesday December 28th, 2010 15. */ 16.public class FTPUtils { 17
3、. private Logger log = Logger.getLogger(this.getClass()); 18. private static FTPUtils ftp; 19. /** 20. * FTP服务地址 21. */ 22. private static String ADDRESS = PropUtils.getString("ftp_server_address"); 23. /** 24. * FTP登录用户名 25.
4、 */ 26. private static String USERNAME = PropUtils.getString("ftp_server_username"); 27. /** 28. * FTP登录密码 29. */ 30. private static String PASSWORD = PropUtils.getString("ftp_server_password"); 31. /** 32. * 构造方法 33. */
5、 1. protected FTPUtils() { 2. } 3. /** 4. * 实例化对象 5. * 6. * @return 7. */ 8. public static FTPUtils getInstance() { 9. if (ftp == null) { 10. ftp = new FTPUtils(); 11. } 12. return ftp;
6、13. } 14. /** 15. * 获取FTP客户端对象 16. * 17. * @return 18. * @throws Exception 19. */ 20. private FTPClient getClient() throws Exception { 21. FTPClient client = new FTPClient(); 22. client.setCharset("utf-8");
7、23. client.setType(FTPClient.TYPE_BINARY); 24. URL url = new URL(FTPUtils.ADDRESS); 25. int port = url.getPort() < 1 ? 21 : url.getPort(); 26. log.info("Ftp server listening on address " + url.toString()); 27. client.
8、connect(url.getHost(), port); 28. client.login(FTPUtils.USERNAME, FTPUtils.PASSWORD); 29. return client; 30. } 31. /** 32. * 注销客户端连接 33. * 34. * @param client 35. *
此文档下载收益归作者所有