FTPClient类的API
org.apache.commons.NET.ftp
Class FTPClient类FTPClient
java.lang.Object java.lang.Object继承
org.apache.commons.net.SocketClient org.apache.commons.net.SocketClient
org.apache.commons.net.ftp.FTP org.apache.commons.net.ftp.FTP
org.apache.commons.net.ftp.FTPClient org.apache.commons.Net.ftp.FTPClient
All Implemented Interfaces: 所有已实现的接口:
Direct Known Subclasses: 直接已知子类:
FTPHTTPClient , FTPSClient FTPHTTPClient , FTPSClient
public class FTPClient公共类FTPClient
implements Configurable实现了可配置
FTPClient encapsulates all the functionality necessary to store and retrieve files from an FTP server. FTPClient封装了所有必要的功能来存储和检索从FTP服务器上的文件。 This class takes care of all low level details of interacting with an FTP server and provides a convenient higher level interface.这个类负责所有与FTP服务器交互的底层细节,并提供了便捷的更高层次的接口。 As with all classes derived from SocketClient , you must first connect to the server with connect before doing anything, and finally disconnect after you're completely finished interacting with the server.正如来自所有类SocketClient ,您必须首先连接到与服务器connect做任何事之前,最后disconnect完成后,你完全与服务器交互。 Then you need to check the FTP reply code to see if the connection was successful.然后,你需要检查的FTP答复代码,看看是否连接成功。 For example:例如:
boolean error = false;布尔错误= 0;
try {尝试{
int reply;诠释答复;
ftp.connect("ftp.foobar.com"); ftp.connect(“ftp.foobar.com”);
System.out.println("Connected to " + server + "."); System.out.println(“连接到”+服务器+ ".");
System.out.print(ftp.getReplyString()); System.out.print(ftp.getReplyString());
// After connection attempt, you should check the reply code to verify / /连接尝试后,你应该检查代码以验证答复
// success. / /成功。
reply = ftp.getReplyCode();答复= ftp.getReplyCode();
if(!FTPReply.isPositiveCompletion(reply)) {如果(!FTPReply.isPositiveCompletion(回复)){
ftp.disconnect(); ftp.disconnect();
System.err.println("FTP server refused connection."); System.err.println(“FTP服务器拒绝连接。”);
System.exit(1); System.exit(1);
} }
... ... // transfer files / /传送文件
ftp.logout(); ftp.logout();
} catch(IOException e) { }捕捉(IOException异常五){
error = true;误差为真;
e.printStackTrace(); e.printStackTrace();
} finally {最后} {
if(ftp.isConnected()) {如果(ftp.isConnected()){
try {尝试{
ftp.disconnect(); ftp.disconnect();
} catch(IOException ioe) { }捕捉(IOException异常雇主组织){
// do nothing / /什么也不做
} }
} }
System.exit(error ? 1 : 0); System.exit(错误1:0?);
} }
Immediately after connecting is the only real time you need to check the reply code (because connect is of type void).连接后立即是唯一真正的时候你需要检查答复代码(因为是连接类型为void)。 The convention for all the FTP command methods in FTPClient is such that they either return a boolean value or some other value.对于所有的FTP FTPClient指挥方法的公约就是这样,他们要么返回一个布尔值或其他值。 The boolean methods return true on a successful completion reply from the FTP server and false on a reply resulting in an error condition or failure.该方法返回一个布尔从FTP服务器成功完成答辩,假假真真的错误条件中的一个或故障而导致的答复。 The methods returning a value other than boolean return a value containing the higher level data produced by the FTP command, or null if a reply resulted in an error condition or failure.该方法返回一个布尔值返回值比含有较高水平的FTP命令,或者为null,如果产生一个错误条件答复或故障导致其他数据。 If you want to access the exact FTP reply code causing a success or failure, you must call getReplyCode after a success or failure.如果您要访问的FTP的确切答复代码导致成功或失败,你必须调用getReplyCode后,成功或失败。
The default settings for FTPClient are for it to use FTP.ASCII_FILE_TYPE , FTP.NON_PRINT_TEXT_FORMAT , FTP.STREAM_TRANSFER_MODE , and FTP.FILE_STRUCTURE . FTPClient的默认设置是它使用FTP.ASCII_FILE_TYPE , FTP.NON_PRINT_TEXT_FORMAT , FTP.STREAM_TRANSFER_MODE和FTP.FILE_STRUCTURE 。 The only file types directly supported are FTP.ASCII_FILE_TYPE and FTP.BINARY_FILE_TYPE .唯一的文件直接支持的类型是FTP.ASCII_FILE_TYPE和FTP.BINARY_FILE_TYPE 。 Because there are at least 4 different EBCDIC encodings, we have opted not to provide direct support for EBCDIC.因为至少有4种不同的EBCDIC编码,我们还选择了不提供直接支持的EBCDIC。 To transfer EBCDIC and other unsupported file types you must create your own filter InputStreams and OutputStreams and wrap them around the streams returned or required by the FTPClient methods.为了转移EBCDIC和其他不支持的文件类型,你必须创建自己的过滤InputStreams和OutputStreams和总结他们周围的流退回或由FTPClient方法所需。 FTPClient uses the NetASCII filter streams to provide transparent handling of ASCII files. FTPClient使用NetASCII过滤器流提供ASCII文件透明处理。 We will consider incorporating EBCDIC support if there is enough demand.我们会考虑把EBCDIC码的支持,如果有足够的需求。
FTP.NON_PRINT_TEXT_FORMAT , FTP.STREAM_TRANSFER_MODE , and FTP.FILE_STRUCTURE are the only supported formats, transfer modes, and file structures. FTP.NON_PRINT_TEXT_FORMAT , FTP.STREAM_TRANSFER_MODE和FTP.FILE_STRUCTURE是唯一支持的格式,传输模式和文件结构。
Because the handling of sockets on different platforms can differ significantly, the FTPClient automatically issues a new PORT (or EPRT) command prior to every transfer requiring that the server connect to the client's data port.由于在不同平台上插座处理可以显着差异,在FTPClient自动发出一个新的端口(或EPRT)命令之前,每次传输要求的服务器连接到客户端的数据端口。 This ensures identical problem-free behavior on Windows, Unix, and Macintosh platforms.这将确保相同的Windows,Unix和Macintosh平台无故障的行为。 Additionally, it relieves programmers from having to issue the PORT (or EPRT) command themselves and dealing with platform dependent issues.此外,它解除不必发出端口(或EPRT)命令自己和与平台有关问题的程序员。
Additionally, for security purposes, all data connections to the client are verified to ensure that they originated from the intended party (host and port).此外,为了安全起见,所有的数据连接到客户端进行验证,以确保他们打算从党(主机和端口)起源。 If a data connection is initiated by an unexpected party, the command will close the socket and throw an IOException.如果一个数据连接是由党发起的一个意外,该命令将关闭套接字并抛出一个IOException异常。 You may disable this behavior with setRemoteVerificationEnabled() .您可以禁用此行为setRemoteVerificationEnabled()
You should keep in mind that the FTP server may choose to prematurely close a connection if the client has been idle for longer than a given time period (usually 900 seconds).你应该记住,在FTP服务器可以选择过早关闭连接,如果客户已超过给定的时间较长时期(通常为900秒)闲置。 The FTPClient class will detect a premature FTP server connection closing when it receives a FTPReply.SERVICE_NOT_AVAILABLE response to a command.将检测的FTPClient类FTP服务器连接过早关闭,当它收到FTPReply.SERVICE_NOT_AVAILABLE响应命令。 When that occurs, the FTP class method encountering that reply will throw an FTPConnectionClosedException . FTPConnectionClosedException is a subclass of IOException and therefore need not be caught separately, but if you are going to catch it separately, its catch block must appear before the more general IOException catch block.一旦这种情况发生时,FTP类方法遇到的答复将抛出一个FTPConnectionClosedException 。 FTPConnectionClosedException是一个子类IOException ,因此不必分别被捕获,但如果你要抓住它分开,它的catch块必须出现在更一般的IOException catch块。 When you encounter an FTPConnectionClosedException , you must disconnect the connection with disconnect() to properly clean up the system resources used by FTPClient.当你遇到一个FTPConnectionClosedException ,必须断开与连接disconnect()妥善清理,系统资源使用FTPClient。 Before disconnecting, you may check the last reply code and text with getReplyCode , getReplyString , and getReplyStrings .在断开,你可以检查代码和文本的最后答复与getReplyCode , getReplyString和getReplyStrings 。 You may avoid server disconnections while the client is idle by periodically sending NOOP commands to the server.您可能会避免服务器断开,而客户端闲置的空操作指令通过定期发送到服务器。
Rather than list it separately for each method, we mention here that every method communicating with the server and throwing an IOException can also throw a MalformedServerReplyException , which is a subclass of IOException.它不是单独列出每个方法,我们在这里提到的每个方法与服务器通信,并抛出一个IOException异常也可引发MalformedServerReplyException ,这是一个IOException异常子类。 A MalformedServerReplyException will be thrown when the reply received from the server deviates enough from the protocol specification that it cannot be interpreted in a useful manner despite attempts to be as lenient as possible.将抛出一个MalformedServerReplyException答复时,从服务器收到的偏离足够的协议规范,它不能在一个有用的方式解释尽管试图尽可能宽松。
Listing API Examples Both paged and unpaged examples of directory listings are available, as follows:上市API的两个例子的目录列表分页和无页数的范例,如下:
Unpaged (whole list) access, using a parser accessible by auto-detect:无页数(全名单)访问,使用分析器可经自动检测:
FTPClient f = new FTPClient(); FTPClient f =new FTPClient();
f.connect(server); f.connect(服务器);
f.login(username, password); f.login(用户名,密码);
FTPFile[] files = listFiles(directory); FTPFile []文件= listfiles <套件(目录);
Paged access, using a parser not accessible by auto-detect.分页访问,使用分析器无法访问的自动检测。 The class defined in the first parameter of initateListParsing should be derived from org.apache.commons.net.FTPFileEntryParser:在应该从org.apache.commons.net.FTPFileEntryParser派生initateListParsing第一个参数定义的类:
FTPClient f = new FTPClient(); FTPClient f =new FTPClient();
f.connect(server); f.connect(服务器);
f.login(username, password); f.login(用户名,密码);
FTPListParseEngine engine = FTPListParseEngine引擎=
f.initiateListParsing("com.whatever.YourOwnParser", directory); f.initiateListParsing(“com.whatever.YourOwnParser”,目录);
while (engine.hasNext()) {而(engine.hasNext()){
FTPFile[] files = engine.getNext(25); // "page size" you want FTPFile []文件= engine.getNext(25); / /“页面大小”你想要
//do whatever you want with these files, display them, etc. / /做你想做这些文件,显示它们,等
//expensive FTPFile objects not created until needed. / /昂贵FTPFile不创建对象,直到需要。
} }
Paged access, using a parser accessible by auto-detect:分页访问,使用分析器可经自动检测:
FTPClient f = new FTPClient(); FTPClient f =new FTPClient();
f.connect(server); f.connect(服务器);
f.login(username, password); f.login(用户名,密码);
FTPListParseEngine engine = f.initiateListParsing(directory); FTPListParseEngine engine = f.initiateListParsing(目录);
while (engine.hasNext()) {而(engine.hasNext()){
FTPFile[] files = engine.getNext(25); // "page size" you want FTPFile []文件= engine.getNext(25); / /“页面大小”你想要
//do whatever you want with these files, display them, etc. / /做你想做这些文件,显示它们,等
//expensive FTPFile objects not created until needed. / /昂贵FTPFile不创建对象,直到需要。
} }
For examples of using FTPClient on servers whose directory listings有关使用服务器上的目录清单FTPClient例子
· use languages other than English使用英语以外的语言
· use date formats other than the American English "standard" MM d yyyy使用日期格式“以外的美国英语”标准MM d yyyy
· are in different timezones and you need accurate timestamps for dependency checking as in Ant在不同的时区,你需要在蚁群依赖检查准确的时间戳
see FTPClientConfig .见FTPClientConfig 。
Author: 作者:
Daniel F. Savarese, Rory Winston丹尼尔楼Savarese,罗里温斯顿
See Also: 另见:
FTP , FTPConnectionClosedException , FTPFileEntryParser , FTPFileEntryParserFactory , DefaultFTPFileEntryParserFactory , FTPClientConfig , MalformedServerReplyException FTP , FTPConnectionClosedException , FTPFileEntryParser , FTPFileEntryParserFactory , DefaultFTPFileEntryParserFactory , FTPClientConfig , MalformedServerReplyException
Field Summary 字段摘要 |
|
static int |
ACTIVE_LOCAL_DATA_CONNECTION_MODE |
static int |
ACTIVE_REMOTE_DATA_CONNECTION_MODE |
static int |
PASSIVE_LOCAL_DATA_CONNECTION_MODE |
static int |
PASSIVE_REMOTE_DATA_CONNECTION_MODE |
Fields inherited from class org.apache.commons.net.ftp. FTP org.apache.commons.net.ftp类从继承的字段。 的FTP |
_commandSupport_ , _controlEncoding , _controlInput_ , _controlOutput_ , _newReplyString , _replyCode , _replyLines , _replyString , ASCII_FILE_TYPE , BINARY_FILE_TYPE , BLOCK_TRANSFER_MODE , CARRIAGE_CONTROL_TEXT_FORMAT , COMPRESSED_TRANSFER_MODE , DEFAULT_CONTROL_ENCODING , DEFAULT_DATA_PORT , DEFAULT_PORT , EBCDIC_FILE_TYPE , FILE_STRUCTURE , LOCAL_FILE_TYPE , NON_PRINT_TEXT_FORMAT , PAGE_STRUCTURE , RECORD_STRUCTURE , STREAM_TRANSFER_MODE , strictMultilineParsing , TELNET_TEXT_FORMAT |
Fields inherited from class org.apache.commons.net. SocketClient org.apache.commons.net类从继承的字段。 SocketClient |
_defaultPort_ , _input_ , _output_ , _serverSocketFactory_ , _socket_ , _socketFactory_ , _timeout_ , connectTimeout , NETASCII_EOL |
Constructor Summary 构造方法摘要 |
|
FTPClient () |
Method Summary 方法摘要 |
|
protected void |
_connectAction_ () |
protected Socket |
_openDataConnection_ (int command, String arg) |
boolean |
abort () |
boolean |
allocate (int bytes) |
boolean |
allocate (int bytes, int recordSize) |
boolean |
appendFile ( String remote, InputStream local) |
appendFileStream ( String remote) |
|
boolean |
changeToParentDirectory () |
boolean |
changeWorkingDirectory ( String pathname) |
boolean |
completePendingCommand () |
void |
configure ( FTPClientConfig config) |
boolean |
deleteFile ( String pathname) |
void |
disconnect () |
void |
enterLocalActiveMode () |
void |
enterLocalPassiveMode () |
boolean |
enterRemoteActiveMode ( InetAddress host, int port) |
boolean |
enterRemotePassiveMode () |
boolean |
features () |
int |
getBufferSize () |
int |
getDataConnectionMode () |
protected String |
getListArguments ( String pathname) |
boolean |
|
getModificationTime ( String pathname) |
|
getPassiveHost () |
|
int |
getPassivePort () |
long |
getRestartOffset () |
getStatus () |
|
getStatus ( String pathname) |
|
getSystemName () |
|
getSystemType () |
|
initiateListParsing () |
|
initiateListParsing ( String pathname) |
|
initiateListParsing ( String parserKey, String pathname) |
|
boolean |
isRemoteVerificationEnabled () |
boolean |
isUseEPSVwithIPv4 () |
FTPFile [] |
listFiles () |
FTPFile [] |
listFiles ( String pathname) |
FTPFile [] |
listFiles ( String pathname, FTPFileFilter filter) |
listHelp () |
|
listHelp ( String command) |
|
String [] |
listNames () |
String [] |
listNames ( String pathname) |
boolean |
login ( String username, String password) |
boolean |
login ( String username, String password, String account) |
boolean |
logout () |
boolean |
makeDirectory ( String pathname) |
printWorkingDirectory () |
|
boolean |
remoteAppend ( String filename) |
boolean |
remoteRetrieve ( String filename) |
boolean |
remoteStore ( String filename) |
boolean |
remoteStoreUnique () |
boolean |
remoteStoreUnique ( String filename) |
boolean |
removeDirectory ( String pathname) |
boolean |
rename ( String from, String to) |
boolean |
retrieveFile ( String remote, OutputStream local) |
retrieveFileStream ( String remote) |
|
boolean |
sendNoOp () |
boolean |
sendSiteCommand ( String arguments) |
void |
setActiveExternalIPAddress ( String ipAddress) |
void |
setActivePortRange (int minPort, int maxPort) |
void |
setBufferSize (int bufSize) |
void |
setDataTimeout (int timeout) |
boolean |
setFileStructure (int structure) |
boolean |
setFileTransferMode (int mode) |
boolean |
setFileType (int fileType) |
boolean |
setFileType (int fileType, int formatOrByteSize) |
void |
setListHiddenFiles (boolean listHiddenFiles) |
boolean |
setModificationTime ( String pathname, String timeval) |
void |
setParserFactory ( FTPFileEntryParserFactory parserFactory) |
void |
setRemoteVerificationEnabled (boolean enable) |
void |
setRestartOffset (long offset) |
void |
setUseEPSVwithIPv4 (boolean selected) |
boolean |
storeFile ( String remote, InputStream local) |
storeFileStream ( String remote) |
|
boolean |
storeUniqueFile ( InputStream local) |
boolean |
storeUniqueFile ( String remote, InputStream local) |
storeUniqueFileStream () |
|
storeUniqueFileStream ( String remote) |
|
boolean |
structureMount ( String pathname) |
FTPClient类的API的更多相关文章
- ftp中ftpClient类的API
org.apache.commons.NET.ftp Class FTPClient类FTPClient java.lang.Object java.lang.Object继承 org.apache ...
- 一个能快速写出实体类的Api文档管理工具
今天各种MVC框架满天飞,大大降低了编码的难度,写实体类就没有办法回避的一件事了,花大把的时间去做一些重复而且繁琐的工作,实在不是一个优秀程序员的作风,所以多次查找和尝试后,找到一个工具类网站——Ap ...
- Java之String类常用API
目录 Java之String类常用API char chatAt(int index) int length() char[] toCharArray() String(char value[]) S ...
- Java,面试题,简历,Linux,大数据,常用开发工具类,API文档,电子书,各种思维导图资源,百度网盘资源,BBS论坛系统 ERP管理系统 OA办公自动化管理系统 车辆管理系统 各种后台管理系统
Java,面试题,简历,Linux,大数据,常用开发工具类,API文档,电子书,各种思维导图资源,百度网盘资源BBS论坛系统 ERP管理系统 OA办公自动化管理系统 车辆管理系统 家庭理财系统 各种后 ...
- 一个 C# 获取高精度时间类(调用API QueryP*)
如果你觉得用 DotNet 自带的 DateTime 获取的时间精度不够,解决的方法是通过调用 QueryPerformanceFrequency 和 QueryPerformanceCounter这 ...
- 1、File类的API
通过Api我们可知,File类是java一个内置类,被封装到java.io.jar包中 其构造方法有一下3种 其方法常用的有以下几种
- Visual C++中最常用的类与API函数
这篇文章能让初学者快速了解visual C++ MFC中常见的核心的类与函数,虽然全部看下来有点枯燥,但对初学者快速了解MFC的框架结构很有好处. 常用类 CArchive类:用于二进制保存档案 CB ...
- 并发基础(二) Thread类的API总结
Thread 类是java中的线程类,提供给用户用于创建.操作线程.获取线程的信息的类.是java线程一切的基础,掌握这个类是非常必须的,先来看一下它的API: 1.字段摘要 static int M ...
- jmeter常见参数 vars、prev、ctx 、props 类的api
ctx - ( JMeterContext) - gives access to the context vars - ( JMeterVariables) - gives read/write ac ...
随机推荐
- NFS服务、SSHD服务
本章内容: NFS服务 SSHD服务 NFS服务 NFS(Network File System)即网络文件系统,用以在网络上与他人共享文件和目录:NFS是运行在应用层的协议:基于Client/Ser ...
- LIS(nlogn)算法描述//线性DP经典类型
题目描述 某国为了防御敌国的导弹袭击,发展出一种导弹拦截系统.但是这种导弹拦截系统有一个缺陷:虽然它的第一发炮弹能够到达任意的高度,但是以后每一发炮弹都不能高于前一发的高度.某天,雷达捕捉到敌国的导弹 ...
- zoj2112 Dynamic Rankings (主席树 || 树套树)
The Company Dynamic Rankings has developed a new kind of computer that is no longer satisfied with t ...
- Codeforces Round #689 (Div. 2, based on Zed Code Competition) E. Water Level (贪心好题)
题意:你在一家公司工作\(t\)天,负责给饮水机灌水,饮水机最初有\(k\)升水,水的范围必须要在\([l,r]\)内,同事每天白天都会喝\(x\)升水,你在每天大清早可以给饮水机灌\(y\)升水,问 ...
- Codeforces Round #641 div2 B. Orac and Models (DP)
题意:有一个长度为\(n\)的序列\(a\),求一个最长上升子序列,且这个子序列的元素在\(a\)中的位置满足\(i_{j+1}modi_{j}=0\),求这个子序列的最大长度. 题意:这题假如我们用 ...
- Shell 信号处理 & Expect 免交互
监控脚本项目 信号处理 1 什么是信号 由键盘组合键或者 kill 命令发出操作称之为信号 信号是发送给进程的,进程在收到信号后会作出默认的响应 2 为何要在进程内处理信号 进程在收到信号后会有默认的 ...
- 关于free和delete的使用
上一篇篇幅太长,这里再区分free和delete的用法. 两个同时存在是有它的原因的,我们前面说过,free是函数,它只释放内存,但不会调用析构函数,如果用free去释放new申请的空间,会因为无法调 ...
- HDU 6704 K-th occurrence(主席树 + RMQ + 后缀数组)题解
题意: 给一个串\(S\),\(length\leq 1e5\),\(Q\leq1e5\)个询问,每次询问输出和\(S_lS_{l+1}\dots S_r\)长得一模一样的第\(k\)个子串的开头位置 ...
- 9. Lock wait timeout exceeded
一. 现象 用户打开消息推送有概率报错,后续发现推送消息阅读数.点赞数无法正常更新,mysql报警有行锁, DBA抓到有锁表语句,kill该语句未正常恢复,elk日志有大量的java.sql.SQLE ...
- 008.NET5_IIS安装教程
控制面板->程序->启动或关闭Windows功能