Save This Page
Home » commons-net-2.0-src » org.apache.commons.net.ftp » [javadoc | source]
org.apache.commons.net.ftp
public class: FTP [javadoc | source]
java.lang.Object
   org.apache.commons.net.SocketClient
      org.apache.commons.net.ftp.FTP

Direct Known Subclasses:
    FTPClient2, FTPSClient, FTPClient

FTP provides the basic the functionality necessary to implement your own FTP client. It extends org.apache.commons.net.SocketClient since extending TelnetClient was causing unwanted behavior (like connections that did not time out properly).

To derive the full benefits of the FTP class requires some knowledge of the FTP protocol defined in RFC 959. However, there is no reason why you should have to use the FTP class. The org.apache.commons.net.ftp.FTPClient class, derived from FTP, implements all the functionality required of an FTP client. The FTP class is made public to provide access to various FTP constants and to make it easier for adventurous programmers (or those with special needs) to interact with the FTP protocol and implement their own clients. A set of methods with names corresponding to the FTP command names are provided to facilitate this interaction.

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). The FTP class will detect a premature FTP server connection closing when it receives a FTPReply.SERVICE_NOT_AVAILABLE response to a command. When that occurs, the FTP class method encountering that reply will throw an org.apache.commons.net.ftp.FTPConnectionClosedException . FTPConectionClosedException 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. When you encounter an org.apache.commons.net.ftp.FTPConnectionClosedException , you must disconnect the connection with disconnect() to properly clean up the system resources used by FTP. Before disconnecting, you may check the last reply code and text with getReplyCode , getReplyString , and getReplyStrings . You may avoid server disconnections while the client is idle by periodicaly 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 org.apache.commons.net.MalformedServerReplyException , which is a subclass of 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.

Field Summary
public static final  int DEFAULT_DATA_PORT    The default FTP data port (20). 
public static final  int DEFAULT_PORT    The default FTP control port (21). * 
public static final  int ASCII_FILE_TYPE    A constant used to indicate the file(s) being transfered should be treated as ASCII. This is the default file type. All constants ending in FILE_TYPE are used to indicate file types. 
public static final  int EBCDIC_FILE_TYPE    A constant used to indicate the file(s) being transfered should be treated as EBCDIC. Note however that there are several different EBCDIC formats. All constants ending in FILE_TYPE are used to indicate file types. 
public static final  int BINARY_FILE_TYPE    A constant used to indicate the file(s) being transfered should be treated as a binary image, i.e., no translations should be performed. All constants ending in FILE_TYPE are used to indicate file types. ** 
public static final  int LOCAL_FILE_TYPE    A constant used to indicate the file(s) being transfered should be treated as a local type. All constants ending in FILE_TYPE are used to indicate file types. ** 
public static final  int NON_PRINT_TEXT_FORMAT    A constant used for text files to indicate a non-print text format. This is the default format. All constants ending in TEXT_FORMAT are used to indicate text formatting for text transfers (both ASCII and EBCDIC). 
public static final  int TELNET_TEXT_FORMAT    A constant used to indicate a text file contains format vertical format control characters. All constants ending in TEXT_FORMAT are used to indicate text formatting for text transfers (both ASCII and EBCDIC). ** 
public static final  int CARRIAGE_CONTROL_TEXT_FORMAT    A constant used to indicate a text file contains ASA vertical format control characters. All constants ending in TEXT_FORMAT are used to indicate text formatting for text transfers (both ASCII and EBCDIC). ** 
public static final  int FILE_STRUCTURE    A constant used to indicate a file is to be treated as a continuous sequence of bytes. This is the default structure. All constants ending in _STRUCTURE are used to indicate file structure for file transfers. * 
public static final  int RECORD_STRUCTURE    A constant used to indicate a file is to be treated as a sequence of records. All constants ending in _STRUCTURE are used to indicate file structure for file transfers. ** 
public static final  int PAGE_STRUCTURE    A constant used to indicate a file is to be treated as a set of independent indexed pages. All constants ending in _STRUCTURE are used to indicate file structure for file transfers. ** 
public static final  int STREAM_TRANSFER_MODE    A constant used to indicate a file is to be transfered as a stream of bytes. This is the default transfer mode. All constants ending in TRANSFER_MODE are used to indicate file transfer modes. ** 
public static final  int BLOCK_TRANSFER_MODE    A constant used to indicate a file is to be transfered as a series of blocks. All constants ending in TRANSFER_MODE are used to indicate file transfer modes. ** 
public static final  int COMPRESSED_TRANSFER_MODE    A constant used to indicate a file is to be transfered as FTP compressed data. All constants ending in TRANSFER_MODE are used to indicate file transfer modes. ** 
public static final  String DEFAULT_CONTROL_ENCODING    The default character encoding used for communicating over an FTP control connection. The default encoding is an ASCII-compatible encoding. Some FTP servers expect other encodings. You can change the encoding used by an FTP instance with setControlEncoding
protected  int _replyCode     
protected  ArrayList<String> _replyLines     
protected  boolean _newReplyString     
protected  String _replyString     
protected  String _controlEncoding     
protected  boolean strictMultilineParsing    This is used to signal whether a block of multiline responses beginning with xxx must be terminated by the same numeric code xxx See section 4.2 of RFX 959 for details. 
protected  BufferedReader _controlInput_    Wraps SocketClient._input_ to facilitate the writing of text to the FTP control connection. Do not access the control connection via SocketClient._input_. This member starts with a null value, is initialized in #_connectAction_ , and set to null in #disconnect
protected  BufferedWriter _controlOutput_    Wraps SocketClient._output_ to facilitate the reading of text from the FTP control connection. Do not access the control connection via SocketClient._output_. This member starts with a null value, is initialized in #_connectAction_ , and set to null in #disconnect
protected  ProtocolCommandSupport _commandSupport_    A ProtocolCommandSupport object used to manage the registering of ProtocolCommandListeners and te firing of ProtocolCommandEvents. ** 
Fields inherited from org.apache.commons.net.SocketClient:
NETASCII_EOL,  _timeout_,  _socket_,  _defaultPort_,  _input_,  _output_,  _socketFactory_,  _serverSocketFactory_,  connectTimeout
Constructor:
 public FTP() 
Method from org.apache.commons.net.ftp.FTP Summary:
_connectAction_,   abor,   acct,   addProtocolCommandListener,   allo,   allo,   appe,   cdup,   cwd,   dele,   disconnect,   getControlEncoding,   getReply,   getReplyCode,   getReplyString,   getReplyStrings,   help,   help,   isStrictMultilineParsing,   list,   list,   mdtm,   mkd,   mode,   nlst,   nlst,   noop,   pass,   pasv,   port,   pwd,   quit,   rein,   removeProtocolCommandListener,   rest,   retr,   rmd,   rnfr,   rnto,   sendCommand,   sendCommand,   sendCommand,   sendCommand,   setControlEncoding,   setStrictMultilineParsing,   site,   smnt,   stat,   stat,   stor,   stou,   stou,   stru,   syst,   type,   type,   user
Methods from org.apache.commons.net.SocketClient:
_connectAction_,   connect,   connect,   connect,   connect,   connect,   connect,   disconnect,   getConnectTimeout,   getDefaultPort,   getDefaultTimeout,   getLocalAddress,   getLocalPort,   getRemoteAddress,   getRemotePort,   getSoLinger,   getSoTimeout,   getTcpNoDelay,   isConnected,   setConnectTimeout,   setDefaultPort,   setDefaultTimeout,   setReceiveBufferSize,   setSendBufferSize,   setServerSocketFactory,   setSoLinger,   setSoTimeout,   setSocketFactory,   setTcpNoDelay,   verifyRemote
Methods from java.lang.Object:
clone,   equals,   finalize,   getClass,   hashCode,   notify,   notifyAll,   toString,   wait,   wait,   wait
Method from org.apache.commons.net.ftp.FTP Detail:
 protected  void _connectAction_() throws IOException 
 public int abor() throws IOException 
    A convenience method to send the FTP ABOR command to the server, receive the reply, and return the reply code.

 public int acct(String account) throws IOException 
    A convenience method to send the FTP ACCT command to the server, receive the reply, and return the reply code.

 public  void addProtocolCommandListener(ProtocolCommandListener listener) 
 public int allo(int bytes) throws IOException 
    A convenience method to send the FTP ALLO command to the server, receive the reply, and return the reply code.

 public int allo(int bytes,
    int recordSize) throws IOException 
    A convenience method to send the FTP ALLO command to the server, receive the reply, and return the reply code.

 public int appe(String pathname) throws IOException 
    A convenience method to send the FTP APPE command to the server, receive the reply, and return the reply code. Remember, it is up to you to manage the data connection. If you don't need this low level of access, use org.apache.commons.net.ftp.FTPClient , which will handle all low level details for you.

 public int cdup() throws IOException 
    A convenience method to send the FTP CDUP command to the server, receive the reply, and return the reply code.

 public int cwd(String directory) throws IOException 
    A convenience method to send the FTP CWD command to the server, receive the reply, and return the reply code.

 public int dele(String pathname) throws IOException 
    A convenience method to send the FTP DELE command to the server, receive the reply, and return the reply code.

 public  void disconnect() throws IOException 
    Closes the control connection to the FTP server and sets to null some internal data so that the memory may be reclaimed by the garbage collector. The reply text and code information from the last command is voided so that the memory it used may be reclaimed. Also sets #_controlInput_ and #_controlOutput_ to null.

 public String getControlEncoding() 
 public int getReply() throws IOException 
    Fetches a reply from the FTP server and returns the integer reply code. After calling this method, the actual reply text can be accessed from either calling getReplyString or getReplyStrings . Only use this method if you are implementing your own FTP client or if you need to fetch a secondary response from the FTP server.

 public int getReplyCode() 
    Returns the integer value of the reply code of the last FTP reply. You will usually only use this method after you connect to the FTP server to check that the connection was successful since connect is of type void.

 public String getReplyString() 
    Returns the entire text of the last FTP server response exactly as it was received, including all end of line markers in NETASCII format.

 public String[] getReplyStrings() 
    Returns the lines of text from the last FTP server response as an array of strings, one entry per line. The end of line markers of each are stripped from each line.

 public int help() throws IOException 
    A convenience method to send the FTP HELP command to the server, receive the reply, and return the reply code.

 public int help(String command) throws IOException 
    A convenience method to send the FTP HELP command to the server, receive the reply, and return the reply code.

 public boolean isStrictMultilineParsing() 
    Return whether strict multiline parsing is enabled, as per RFX 959, section 4.2.
 public int list() throws IOException 
    A convenience method to send the FTP LIST command to the server, receive the reply, and return the reply code. Remember, it is up to you to manage the data connection. If you don't need this low level of access, use org.apache.commons.net.ftp.FTPClient , which will handle all low level details for you.

 public int list(String pathname) throws IOException 
    A convenience method to send the FTP LIST command to the server, receive the reply, and return the reply code. Remember, it is up to you to manage the data connection. If you don't need this low level of access, use org.apache.commons.net.ftp.FTPClient , which will handle all low level details for you.

 public int mdtm(String file) throws IOException 
 public int mkd(String pathname) throws IOException 
    A convenience method to send the FTP MKD command to the server, receive the reply, and return the reply code.

 public int mode(int mode) throws IOException 
    A convenience method to send the FTP MODE command to the server, receive the reply, and return the reply code.

 public int nlst() throws IOException 
    A convenience method to send the FTP NLST command to the server, receive the reply, and return the reply code. Remember, it is up to you to manage the data connection. If you don't need this low level of access, use org.apache.commons.net.ftp.FTPClient , which will handle all low level details for you.

 public int nlst(String pathname) throws IOException 
    A convenience method to send the FTP NLST command to the server, receive the reply, and return the reply code. Remember, it is up to you to manage the data connection. If you don't need this low level of access, use org.apache.commons.net.ftp.FTPClient , which will handle all low level details for you.

 public int noop() throws IOException 
    A convenience method to send the FTP NOOP command to the server, receive the reply, and return the reply code.

 public int pass(String password) throws IOException 
    A convenience method to send the FTP PASS command to the server, receive the reply, and return the reply code.
 public int pasv() throws IOException 
    A convenience method to send the FTP PASV command to the server, receive the reply, and return the reply code. Remember, it's up to you to interpret the reply string containing the host/port information.

 public int port(InetAddress host,
    int port) throws IOException 
    A convenience method to send the FTP PORT command to the server, receive the reply, and return the reply code.

 public int pwd() throws IOException 
    A convenience method to send the FTP PWD command to the server, receive the reply, and return the reply code.

 public int quit() throws IOException 
    A convenience method to send the FTP QUIT command to the server, receive the reply, and return the reply code.

 public int rein() throws IOException 
    A convenience method to send the FTP REIN command to the server, receive the reply, and return the reply code.

 public  void removeProtocolCommandListener(ProtocolCommandListener listener) 
 public int rest(String marker) throws IOException 
    A convenience method to send the FTP REST command to the server, receive the reply, and return the reply code.

 public int retr(String pathname) throws IOException 
    A convenience method to send the FTP RETR command to the server, receive the reply, and return the reply code. Remember, it is up to you to manage the data connection. If you don't need this low level of access, use org.apache.commons.net.ftp.FTPClient , which will handle all low level details for you.

 public int rmd(String pathname) throws IOException 
    A convenience method to send the FTP RMD command to the server, receive the reply, and return the reply code.

 public int rnfr(String pathname) throws IOException 
    A convenience method to send the FTP RNFR command to the server, receive the reply, and return the reply code.

 public int rnto(String pathname) throws IOException 
    A convenience method to send the FTP RNTO command to the server, receive the reply, and return the reply code.

 public int sendCommand(String command) throws IOException 
    Sends an FTP command with no arguments to the server, waits for a reply and returns the numerical response code. After invocation, for more detailed information, the actual reply text can be accessed by calling getReplyString or getReplyStrings .

 public int sendCommand(int command) throws IOException 
    Sends an FTP command with no arguments to the server, waits for a reply and returns the numerical response code. After invocation, for more detailed information, the actual reply text can be accessed by calling getReplyString or getReplyStrings .

 public int sendCommand(String command,
    String args) throws IOException 
    Sends an FTP command to the server, waits for a reply and returns the numerical response code. After invocation, for more detailed information, the actual reply text can be accessed by calling getReplyString or getReplyStrings .

 public int sendCommand(int command,
    String args) throws IOException 
    Sends an FTP command to the server, waits for a reply and returns the numerical response code. After invocation, for more detailed information, the actual reply text can be accessed by calling getReplyString or getReplyStrings .

 public  void setControlEncoding(String encoding) 
    Sets the character encoding used by the FTP control connection. Some FTP servers require that commands be issued in a non-ASCII encoding like UTF-8 so that filenames with multi-byte character representations (e.g, Big 8) can be specified.
 public  void setStrictMultilineParsing(boolean strictMultilineParsing) 
    Set strict multiline parsing.
 public int site(String parameters) throws IOException 
    A convenience method to send the FTP SITE command to the server, receive the reply, and return the reply code.

 public int smnt(String dir) throws IOException 
    A convenience method to send the FTP SMNT command to the server, receive the reply, and return the reply code.

 public int stat() throws IOException 
    A convenience method to send the FTP STAT command to the server, receive the reply, and return the reply code.

 public int stat(String pathname) throws IOException 
    A convenience method to send the FTP STAT command to the server, receive the reply, and return the reply code.

 public int stor(String pathname) throws IOException 
    A convenience method to send the FTP STOR command to the server, receive the reply, and return the reply code. Remember, it is up to you to manage the data connection. If you don't need this low level of access, use org.apache.commons.net.ftp.FTPClient , which will handle all low level details for you.

 public int stou() throws IOException 
    A convenience method to send the FTP STOU command to the server, receive the reply, and return the reply code. Remember, it is up to you to manage the data connection. If you don't need this low level of access, use org.apache.commons.net.ftp.FTPClient , which will handle all low level details for you.

 public int stou(String pathname) throws IOException 
    A convenience method to send the FTP STOU command to the server, receive the reply, and return the reply code. Remember, it is up to you to manage the data connection. If you don't need this low level of access, use org.apache.commons.net.ftp.FTPClient , which will handle all low level details for you.
 public int stru(int structure) throws IOException 
    A convenience method to send the FTP STRU command to the server, receive the reply, and return the reply code.

 public int syst() throws IOException 
    A convenience method to send the FTP SYST command to the server, receive the reply, and return the reply code.

 public int type(int fileType) throws IOException 
    A convenience method to send the FTP TYPE command to the server, receive the reply, and return the reply code.

 public int type(int fileType,
    int formatOrByteSize) throws IOException 
    A convenience method to send the FTP TYPE command for text files to the server, receive the reply, and return the reply code.
 public int user(String username) throws IOException 
    A convenience method to send the FTP USER command to the server, receive the reply, and return the reply code.