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 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 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
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 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 | |
|---|---|
| static int |
A constant used to indicate the file(s) being transfered should be treated as ASCII. |
| static int |
A constant used to indicate the file(s) being transfered should be treated as a binary image, i.e., no translations should be performed. |
| static int |
A constant used to indicate a file is to be transfered as a series of blocks. |
| static int |
A constant used to indicate a text file contains ASA vertical format control characters. |
| static int |
A constant used to indicate a file is to be transfered as FTP compressed data. |
| static String |
The default character encoding used for communicating over an FTP control connection. |
| static int |
The default FTP data port (20). |
| static int |
The default FTP control port (21). |
| static int |
A constant used to indicate the file(s) being transfered should be treated as EBCDIC. |
| static int |
A constant used to indicate a file is to be treated as a continuous sequence of bytes. |
| static int |
A constant used to indicate the file(s) being transfered should be treated as a binary image, i.e., no translations should be performed. |
| static int |
A constant used to indicate the file(s) being transfered should be treated as a local type. |
| static int |
A constant used for text files to indicate a non-print text format. |
| static int |
A constant used to indicate a file is to be treated as a set of independent indexed pages. |
| static int |
A constant used to indicate a file is to be treated as a sequence of records. |
| static int |
A constant used to indicate a file is to be transfered as a stream of bytes. |
| static int |
A constant used to indicate a text file contains format vertical format control characters. |
| protected ProtocolCommandSupport |
A ProtocolCommandSupport object used to manage the registering of ProtocolCommandListeners and te firing of ProtocolCommandEvents. |
| Fields inherited from org.apache.commons.netSocketClient |
|---|
| Fields inherited from org.apache.commons.net.telnetTelnet |
|---|
| Fields inherited from org.apache.commons.net.telnetTelnetClient |
|---|
| Constructor Summary |
|---|
|
The default FTP constructor. |
| Method Summary | |
|---|---|
| int |
A convenience method to send the FTP ABOR command to the server, receive the reply, and return the reply code. |
| int |
A convenience method to send the FTP ACCT command to the server, receive the reply, and return the reply code. |
| void |
Adds a ProtocolCommandListener. |
| int |
A convenience method to send the FTP ALLO command to the server, receive the reply, and return the reply code. |
| int |
A convenience method to send the FTP ALLO command to the server, receive the reply, and return the reply code. |
| int |
A convenience method to send the FTP APPE command to the server, receive the reply, and return the reply code. |
| int |
A convenience method to send the FTP CDUP command to the server, receive the reply, and return the reply code. |
| int |
A convenience method to send the FTP CWD command to the server, receive the reply, and return the reply code. |
| int |
A convenience method to send the FTP DELE command to the server, receive the reply, and return the reply code. |
| void |
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. |
| String |
No description provided. |
| int |
Fetches a reply from the FTP server and returns the integer reply code. |
| int |
Returns the integer value of the reply code of the last FTP reply. |
| String |
Returns the entire text of the last FTP server response exactly as it was received, including all end of line markers in NETASCII format. |
| String[] |
Returns the lines of text from the last FTP server response as an array of strings, one entry per line. |
| int |
A convenience method to send the FTP HELP command to the server, receive the reply, and return the reply code. |
| int |
A convenience method to send the FTP HELP command to the server, receive the reply, and return the reply code. |
| int |
A convenience method to send the FTP LIST command to the server, receive the reply, and return the reply code. |
| int |
A convenience method to send the FTP LIST command to the server, receive the reply, and return the reply code. |
| int |
A convenience method to send the FTP MKD command to the server, receive the reply, and return the reply code. |
| int |
A convenience method to send the FTP MODE command to the server, receive the reply, and return the reply code. |
| int |
A convenience method to send the FTP NLST command to the server, receive the reply, and return the reply code. |
| int |
A convenience method to send the FTP NLST command to the server, receive the reply, and return the reply code. |
| int |
A convenience method to send the FTP NOOP command to the server, receive the reply, and return the reply code. |
| int |
A convenience method to send the FTP PASS command to the server, receive the reply, and return the reply code. |
| int |
A convenience method to send the FTP PASV command to the server, receive the reply, and return the reply code. |
| int |
A convenience method to send the FTP PORT command to the server, receive the reply, and return the reply code. |
| int |
A convenience method to send the FTP PWD command to the server, receive the reply, and return the reply code. |
| int |
A convenience method to send the FTP QUIT command to the server, receive the reply, and return the reply code. |
| int |
A convenience method to send the FTP REIN command to the server, receive the reply, and return the reply code. |
| void |
Removes a ProtocolCommandListener. |
| int |
A convenience method to send the FTP REST command to the server, receive the reply, and return the reply code. |
| int |
A convenience method to send the FTP RETR command to the server, receive the reply, and return the reply code. |
| int |
A convenience method to send the FTP RMD command to the server, receive the reply, and return the reply code. |
| int |
A convenience method to send the FTP RNFR command to the server, receive the reply, and return the reply code. |
| int |
A convenience method to send the FTP RNTO command to the server, receive the reply, and return the reply code. |
| int |
Sends an FTP command to the server, waits for a reply and returns the numerical response code. |
| int |
Sends an FTP command to the server, waits for a reply and returns the numerical response code. |
| int |
Sends an FTP command with no arguments to the server, waits for a reply and returns the numerical response code. |
| int |
Sends an FTP command with no arguments to the server, waits for a reply and returns the numerical response code. |
| void |
Sets the character encoding used by the FTP control connection. |
| int |
A convenience method to send the FTP SITE command to the server, receive the reply, and return the reply code. |
| int |
A convenience method to send the FTP SMNT command to the server, receive the reply, and return the reply code. |
| int |
A convenience method to send the FTP STAT command to the server, receive the reply, and return the reply code. |
| int |
A convenience method to send the FTP STAT command to the server, receive the reply, and return the reply code. |
| int |
A convenience method to send the FTP STOR command to the server, receive the reply, and return the reply code. |
| int |
A convenience method to send the FTP STOU command to the server, receive the reply, and return the reply code. |
| int |
A convenience method to send the FTP STOU command to the server, receive the reply, and return the reply code. |
| int |
A convenience method to send the FTP STRU command to the server, receive the reply, and return the reply code. |
| int |
A convenience method to send the FTP SYST command to the server, receive the reply, and return the reply code. |
| int |
A convenience method to send the FTP TYPE command for text files to the server, receive the reply, and return the reply code. |
| int |
A convenience method to send the FTP TYPE command to the server, receive the reply, and return the reply code. |
| int |
A convenience method to send the FTP USER command to the server, receive the reply, and return the reply code. |
| protected void |
No description provided. |
| Methods inherited from java.langObject |
|---|
| Methods inherited from org.apache.commons.net.telnetTelnet |
|---|
public static
int
ASCII_FILE_TYPE
public static
int
BINARY_FILE_TYPE
FILE_TYPE are used to
indicate file types.
public static
int
BLOCK_TRANSFER_MODE
TRANSFER_MODE are used
to indicate file transfer modes.
public static
int
CARRIAGE_CONTROL_TEXT_FORMAT
TEXT_FORMAT are used to indicate
text formatting for text transfers (both ASCII and EBCDIC).
public static
int
COMPRESSED_TRANSFER_MODE
TRANSFER_MODE
are used to indicate file transfer modes.
public static
int
EBCDIC_FILE_TYPE
FILE_TYPE
are used to indicate file types.
public static
int
FILE_STRUCTURE
_STRUCTURE are used to indicate file structure for
file transfers.
public static
int
IMAGE_FILE_TYPE
FILE_TYPE are used to
indicate file types.
public static
int
LOCAL_FILE_TYPE
FILE_TYPE are used to indicate file types.
public static
int
NON_PRINT_TEXT_FORMAT
TEXT_FORMAT are used to indicate
text formatting for text transfers (both ASCII and EBCDIC).
public static
int
PAGE_STRUCTURE
_STRUCTURE are used to indicate file structure for file
transfers.
public static
int
RECORD_STRUCTURE
_STRUCTURE
are used to indicate file structure for file transfers.
public static
int
STREAM_TRANSFER_MODE
TRANSFER_MODE are used to indicate file transfer
modes.
public static
int
TELNET_TEXT_FORMAT
TEXT_FORMAT are used to indicate
text formatting for text transfers (both ASCII and EBCDIC).
public FTP
(
)
DEFAULT_PORT and initializes internal data structures
for saving FTP reply information.
public
int
getReplyCode
(
)
connect is of type void.
FILE_TYPEare used to indicate file types.