FTP client 客户端

本文介绍如何使用Java实现FTP客户端功能,包括下载指定文件的过程。通过引入jakarta-oro-2.0.8.jar和commons-net-1.4.1.jar两个依赖库,实现了连接FTP服务器、登录验证及文件下载等功能。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

因为工作需要实现FTP客户端。所以就在网上看了下别人的。自己在这记录下。

要实现FTP客户端需要下载2个JAR。jakarta-oro-2.0.8.jar,和commons-net-1.4.1.jar

	public static void main(String[] args) throws Exception {
		FTPClient ftp = new FTPClient();
		ftp.setControlEncoding("utf-8");
		FTPClientConfig conf = new FTPClientConfig(FTPClientConfig.SYST_NT);  
		conf.setServerLanguageCode("zh"); 
		ftp.connect("10.1.1.249", 21);
		Boolean b=ftp.login("xiaopeng", "xiaopeng");
		int reply=ftp.getReplyCode();
		if(!FTPReply.isPositiveCompletion(reply)){
		}else{
			System.out.println("登录成功");
			ftp.changeWorkingDirectory("leadbank"+File.separator);
			FTPFile f[]=ftp.listFiles();
			for(FTPFile ff:f){
				System.out.println(ff.getName());
				if(ff.getName().equals("Readme.txt")){
					File fi = new File("d:"+File.separator+"Readme.txt");
					if(!fi.exists()){
						
					}else{
						fi.createNewFile();
					}
					OutputStream o = new FileOutputStream(fi);
					BufferedOutputStream buffer = new BufferedOutputStream(o);
					
					ftp.retrieveFile("Readme.txt",buffer);
					buffer.flush();
					buffer.close();
					o.close();
					ftp.logout();
					System.out.println("下载完成退出");
				}
			}
			
		}
	}

mark一下



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值