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

ftp4j之FTP

    博客分类:
  • JAVA
阅读更多

The ftp4j library implements a Java full-features FTP client. With ftp4j embedded in your application you can: transfer files (upload and download), browse the remote FTP site (directory listing included), create, delete, rename and move remote directories and files.

 

 ftp4j类库可支持实现java版的FTP客户端,可应用到你的应用程序中,实现文件的上传下载,浏览远程FTP服务器上的目录和文件,创建、删除、重命,移动远程目录和文件等操作。

 

ftp4j的特点:

 

1、100%免费

2、可远程连接FTP服务器

3、远程操作

4、文件上传下载

5、异常捕获

 

下载路径:http://www.sauronsoftware.it/projects/ftp4j/ftp4j-1.3.1.zip

 

快速上手:

 

The main class of the library is FTPClient (it.sauronsoftware.ftp4j.FTPClient).

Start creating a FTPClient instance:

FTPClient client = new FTPClient();

Connect now to a remote FTP service:

client.connect("ftp.host.com");

If the service port is other than the standard 21:

client.connect("ftp.host.com", port);

In example:

client.connect("ftp.host.com", 8021);

Step now to the login procedure:

client.login("carlo", "mypassword");

If no exception is thrown you are now authenticated to the remote server. Otherwise, if the authentication attempt fails, you receive a it.sauronsoftware.ftp4j.FTPException.

Anonymous authentication, if admitted by the connected service, can be done sending the username "anonymous" and an arbitrary password (note that some servers require an e-mail address in place of the password):

client.login("anonymous", "ftp4j");

Do anything you want with the remote FTP service, then disconnect:

client.disconnect(true);

This one sends the FTP QUIT command to the remote server, requesting a legal disconnect procedure. If you just want to break the connection, without sending any advice to the server, call:

client.disconnect(false);

Connecting through a proxy

The client connects to the server through a connector (an object implementing the it.sauronsoftware.ftp4j.FTPConnector interface), which returns to the client an already open connection (an object implementing the it.sauronsoftware.ftp4j.FTPConnection interface). That is why ftp4j could support a large set of proxies.

The connector for a client instance can be setted with the setConnector() method, obviously before connecting the remote server:

client.setConnector(anyConnectorYouWant);

Browsing the remote site

Get the current directory absolute path calling:

String dir = client.currentDirectory();

Change directory with:

client.changeDirectory(newPath);

You can use both absolute and relative paths:

client.changeDirectory("/an/absolute/one");
client.changeDirectory("relative");

Back to the parent directory with:

client.changeDirectoryUp();

Renaming files and directories

To rename a remote file or directory:

client.rename("oldname", "newname");

Moving files and directories

The rename() method can also be used to move files and directories from a location to another.

In example, think in the current working directory you have a file called "myfile.txt", and you want to move it in the sub-directory "myfolder":

client.rename("myfile.txt", "myfolder/myfile.txt");

Deleting files

To delete a remote file call:

client.deleteFile(relativeOrAbsolutePath);

In example:

client.deleteFile("useless.txt");

Creating and deleting directories

You can create a new directory on the remote site, if the service gives you this oppurtunity:

client.createDirectory("newfolder");

You can also remove an existing one:

client.deleteDirectory(absoluteOrRelativePath);

In example:

client.deleteDirectory("oldfolder");

Please note that usually FTP servers can delete only empty directories.

 

 

Downloading and uploading files

The easiest way to download a remote file is a call to the download(String, File) method:

client.download("remoteFile.ext", new java.io.File("localFile.ext"));

To upload:

client.upload(new java.io.File("localFile.ext"));

 

 

参考文章路径:http://www.sauronsoftware.it/projects/ftp4j/manual.php#3

评论

相关推荐

    ftp4j.jar包

    Ftp4j.jar 包用于开发FTp应用

    ftp4j-一个开源的支持代理的FTP组件

    (不过如果你需要FTPS及SFTP,那ftp4j不支持) jar包只有50多k,地址在这里:ftp4j 使用代理的代码: import java.util.ArrayList; import it.sauronsoftware.ftp4j.FTPClient; import it.sauronsoftware.ftp4j....

    ftp4j-1.3.1下载

    ftp4j是一个FTP客户端Java类库,实现了FTP客户端应具有的大部分功能。可以将ftp4j嵌到你的Java应用中,来传输文件(包括上传和下载),浏览远程FTP服务器上的目录和文件,创建、删除、重命,移动远程目录和文件。ftp...

    android的ftp4j的jar包

    android的ftp4j的jar包

    ftp4j-1.7.2.rar

    FTP(File Transfer Protocol,文件传输协议) 是 TCP/IP 协议组中的协议之一。FTP协议包括两个组成部分,其一为FTP服务器,其二为FTP客户端。其中FTP服务器用来存储文件,用户可以使用FTP客户端通过FTP协议访问位于...

    ftp客户端(ftp4j修改版)

    ftp4j修改版,修正了ftp4j版本在Android终端上释放ftp连接异常的问题

    可用的ftp4j-1.7.2jar包.zip

    可用的ftp4j-1.7.2jar包 , 压缩包解压,提取jar包直接使用,

    ftp4j 1.5手册

    ftp4j 1.5 manual.chm

    ftp4j-1.7.2.jar

    将ftp4j JAR文件添加到你应用程序的classpath中, 然后你就可以自动启用ftp4j类的使用了.

    ftp4j-1.6-支持代理配置

    ftp4j是一个FTP客户端Java类库,实现了FTP客户端应具有的大部分功能。可以将ftp4j嵌到你的Java应用中,来传输文件(包括上传和下载),浏览远程FTP服务器上的目录和文件,创建、删除、重命,移动远程目录和文件。ftp...

    FTP客户端Java类库 ftp4j

    FTP客户端Java类库 ftp4j

    ftp4j使用方法

    FTP工具类(ftp4j)的各个方法的使用说明。

    android 使用ftp上传下载(使用ftp4j)弹出框(进度条)

    android 使用ftp上传下载(使用ftp4j)弹出框(显示上传下载进度条) 只是客户端

    ftp 各种客户端 ftp4j-1.5.1.zip j-ftp-1.52.tar.gz jsch-0.1.43.zip

    ftp4j-1.5.1.zip j-ftp-1.52.tar.gz jsch-0.1.43.zip ftp4j-1.5.1.zip j-ftp-1.52.tar.gz jsch-0.1.43.zip

    ftp4j-1.4.1.jar

    ftp4j-1.4.1.jarftp4j-1.4.1.jarftp4j-1.4.1.jarftp4j-1.4.1.jarftp4j-1.4.1.jarftp4j-1.4.1.jarftp4j-1.4.1.jarftp4j-1.4.1.jar

    ftp4j 1.3源码

    ftp4j源码,可以参考这个做ftps的客户端。

    ftp4j 上传 下载

    完整的帮助文档,中文帮助文档,ftp4j jar包 自己写的一个完整的上传实例。

    基于java的开发源码-FTP客户端Java类库 ftp4j.zip

    基于java的开发源码-FTP客户端Java类库 ftp4j.zip 基于java的开发源码-FTP客户端Java类库 ftp4j.zip 基于java的开发源码-FTP客户端Java类库 ftp4j.zip 基于java的开发源码-FTP客户端Java类库 ftp4j.zip 基于java的...

    ftp4j-1.7.2.zip

    ftp4j-1.7.2.jar支持FTPClient上传以及下载等功能。

    ftp4j 架包 jar

    ftp4j类库可支持实现java版的FTP客户端,可应用到你的应用程序中,实现文件的上传下载,浏览远程FTP服务器上的目录和文件,创建、删除、重命,移动远程目录和文件等操作。 ftp4j的特点: 1、100%免费 2、可远程连接...

Global site tag (gtag.js) - Google Analytics