`
小网客
  • 浏览: 1217500 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

Java通过apache的common包操作ftp

 
阅读更多

场景:

1.获取ftp列表

2.获取文件

实现:

private static void list() {
	FTPClient ftpClient = new FTPClient();

	try {
		ftpClient.connect("ftp.someabcd.com", 21);
		ftpClient.setControlEncoding("UTF-8");
		ftpClient.login("anonymous", "anonymous@ftp.someabcd.com");
		ftpClient.enterLocalPassiveMode();
		ftpClient.setFileType(FTPClient.BINARY_FILE_TYPE);

		FTPFile[] ftpFiles = ftpClient.listFiles("/");
		for (FTPFile ftpFile : ftpFiles) {
			System.out.println(ftpFile.getName());
		}
	} catch (Exception e) {
		e.printStackTrace();
	} finally {
		try {
			ftpClient.disconnect();
        } catch (IOException e) {
            e.printStackTrace();
        }
	}
}

 get文件

private static void get() {
	FTPClient ftpClient = new FTPClient();
	OutputStream is =null;
	try {
		ftpClient.connect("ftp.someabcd.com", 21);
		ftpClient.setControlEncoding("UTF-8");
		ftpClient.login("anonymous", "anonymous@ftp.someabcd.com");
		ftpClient.enterLocalPassiveMode();
		ftpClient.setFileType(FTPClient.BINARY_FILE_TYPE);
		File localFile = new File("G:\\a.txt");
		is = new FileOutputStream(localFile);
		ftpClient.retrieveFile("/temp/128.139.txt", is);
	} catch (Exception e) {
		e.printStackTrace();
	} finally {
		IOUtils.closeQuietly(is);
		try {
			ftpClient.disconnect();
        } catch (IOException e) {
            e.printStackTrace();
        }
	}
}

 其他常用操作:

ftpClient.dele(pathname);
ftpClient.deleteFile(pathname);
ftpClient.storeFile(remote, local);

 

0
4
分享到:
评论

相关推荐

    apache-commons源码及jar文件

    Apache Commons是一个非常有用的工具包,解决各种实际的通用问题。(附件中提供了该工具包的jar包,及源文件以供研究) BeanUtils Commons-BeanUtils 提供对 Java 反射和自省API的包装 Betwixt Betwixt提供将 ...

    java操纵ftp上传的客户端实现

    很简单的代码,主要是借用了apache common开源项目的一个jar包:http://commons.apache.org/net/download_net.cgi,接下来就只要几个简单函数就可以搞定了。

    java版ftp上传下载工具类

    使用apache的common-net.jar,实现ftp文件的上传和下载,封装成工具类,方便开发。

    用于FTP文件传输的命令追踪

    用于java common-net工具包编写FTP文件传输客户端的软件

    各种协议示例代码

    apache common-net FTP Telnet SSH 等示例代码

    前端-后端java的Util类的工具类

    │ │ ftp二进制与ascii传输方式区别.txt │ │ IPDeal.java │ │ Md5.java │ │ MD5Encrypt.java │ │ MyFileFilter.java │ │ PropsUtil.java │ │ RegExUtil.java │ │ SimpleConfig.java │ │ ...

    AWStats- 非常好用Apache,vsftp日志分析工具

    ,如 Apache日志档案 s (NCSA combined/XLF/ELF log format or common/CLF log format), WebStar, IIS (W3C的日志格式)及许多其他网站,Proxy(代理服务器)、Wap、流量服务器、邮件服务器和一些 FTP服务器 . ...

    FTPClient.listFiles()获取文件为空的问题.

    //由于apache不支持中文语言环境,通过定制类解析中文日期类型 ftpClient.configure(new FTPClientConfig("com.zznode.tnms.ra.c11n.nj.resource.ftp.UnixFTPEntryParser")); FTPFile[] files = ftpClient.list...

    pro_apache_third_edition..pdf

    Apache and the Internet..............................................1 Apache: The Anatomy of a Web Server.........................................................1 The Apache Source ....................

    Cassandra-The-Definitive-Guide.pdf

    ers and architects alike can use this common language and catalog of solutions to tackle their integration problems. But although Hohpe and Woolf gave us the theory, the industry still needed an open ...

    iBase4J分布式系统-其他

    技术选型:核心框架:Sring boot + Spring Framework + Dubbo + ibase4j-common安全框架:Apache Shiro任务调度:Spring + Quartz持久层框架:MyBatis + MyBatis-Plus数据库连接池:Alibaba Druid缓存框架:Redis...

Global site tag (gtag.js) - Google Analytics