package com.vakinge.ftp;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.net.SocketException;
import org.apache.commons.net.ftp.FTPClient;
import org.apache.commons.net.ftp.FTPFile;
import org.apache.commons.net.ftp.FTPReply;
public class ClientFtpApp {
private String ip = "localhost";
private int port = 21;
private String username = "ftpuser";
private String password = "123456";
/**
* @param args
*/
public static void main(String[] args) {
ClientFtpApp ftp = new ClientFtpApp();
ftp.downLoadFile("c:\\", "./web/", "Member.asp");
}
public void downLoadFile(String localPath, String remotePath, String fileName) {
FTPFile[] files = null;
FTPClient client = null;
try {
int reply;
if (client == null) {
try {
client = new FTPClient();
client.setControlEncoding("utf-8");
client.setDefaultPort(port);
client.connect(ip, port);
client.login(username, password);
reply = client.getReplyCode();
client.setDataTimeout(120000);
System.out.println(ip + " 连接成功");
if (!FTPReply.isPositiveCompletion(reply)) {
client.disconnect();
System.out.println(ip + " connect refused!");
}
} catch (SocketException e) {
e.printStackTrace();
System.out.println(ip + " 连接超时!");
} catch (IOException e) {
e.printStackTrace();
System.out.println(ip + " 服务器无法打开!");
}
}
client.changeWorkingDirectory(remotePath);
files = client.listFiles();
for (FTPFile f : files) {
if (f.getName().equals(fileName)) {
File localFile = new File(localPath + File.separator
+ fileName);
FileOutputStream fos = new FileOutputStream(localFile);
client.retrieveFile(fileName, fos);
fos.close();
}
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
if (client != null) {
try {
client.logout();
client.disconnect();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
}
随便推荐一个下载jar的网站:http://www.springsource.com/repository/app/
分享到:
相关推荐
org.apache.commons.net.ftp.FTPClient包,不错,在实际项目和产品中使用过。
FTP应用的jar包,主要用于java开发FTP上传下载
org.apache.commons.net.ftp.FTPClient FTP工具类,实现上传、下载、压缩到输出流下载等功能
.net.ftp.FTPClient jar ,exaple, commons-net-2.0.jar
org.apache.commons.net.ftp的官方完整jar包 放心使用
Apache Commons Net » 3.3 org.apache.commons.net.ftp.FTPClient
上传了收集的最新的 commons-io-2.4.jar 包 和 commons-net-3.3.jar 以及 FTP java调用例子。net 包是一个用于操作Internet基础协议(Finger,Whois,TFTP,Telnet,POP3,FTP,NNTP,以及SMTP)的底层API。Net包...
sun.net.ftp.FtpClient,it.sauronsoftware.ftp4j.FTPClient,org.apache.commons.net.ftp.FTPClient三种不同的方式操作FTP
FTPClient封装了所有必要的功能来存储和检索从FTP服务器上的文件。 这个类负责所有与FTP服务器交互的底层细节,并提供了便捷的更高层次的接口。 正如来自所有类SocketClient ,您必须首先连接到与服务器connect做...
Java程序使用Apache的commons-net-3.0.jar包中的org.apache.commons.net.ftp.FTPClient类实现对ftp上传、下载、删除等操作,是一个不错的东西哦
import org.apache.commons.io.IOUtils; import org.apache.commons.net.ftp.FTPClient; import org.apache.commons.net.ftp.FTPFile; import org.apache.commons.net.ftp.FTPReply;
本项目使用org.apache.commons.net.ftp.FTPClient实现文件上传到ftp服务器,解决不能上传中文文件的问题。
该客户端软件使用的是org.apache.commons.net.ftp.FTPClient这个类,FTPClient这个类,该类具体的可查看官网的api文档,链接:FTPClient API,需要自己导入jar包,我下载的是commons-net-3.6.jar,下载链接为...
org.apache.commons.net.ftp.FTPClient的最新jar报
获取ftp服务器文件的大小,从而可以设置下载的进度条
TestFtpUpload 为示例工程 依赖的jar 里面都有 倒入到myeclipse就可使用 ...2. 通过apache:org.apache.commons.net.ftp.FTPClient 3. 通过edtftp: com.enterprisedt.net.ftp.FileTransferClient
基于org.apache.commons.net.ftp.FTPClient; 实现的FTP 上传下载 封装类
org.apache.commons.net.ftp.FTPClient进行上传文件,功能强大 ,可实现文件的上传和下载
Java常用FTP 文件操作 说明 Apache FTPClient ftp4j jftp java中实现ftp 文件上传 文件下载