Class FTP
- Direct Known Subclasses:
- FTPClient
 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 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. 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.
 
- See Also:
- 
Field SummaryFieldsModifier and TypeFieldDescriptionprotected ProtocolCommandSupportA ProtocolCommandSupport object used to manage the registering of ProtocolCommandListeners and the firing of ProtocolCommandEvents.protected Stringprotected BufferedReaderWraps SocketClient._input_ to facilitate the reading of text from the FTP control connection.protected BufferedWriterWraps SocketClient._output_ to facilitate the writing of text to the FTP control connection.protected booleanprotected intprotected Stringstatic final intA constant used to indicate the file(s) being transferred should be treated as ASCII.static final intA constant used to indicate the file(s) being transferred should be treated as a binary image, i.e., no translations should be performed.static final intA constant used to indicate a file is to be transferred as a series of blocks.static final intA constant used to indicate a text file contains ASA vertical format control characters.static final intA constant used to indicate a file is to be transferred as FTP compressed data.static final StringThe default character encoding used for communicating over an FTP control connection.static final intThe default FTP data port (20).static final intThe default FTP control port (21).static final intA constant used to indicate a file is to be transferred as FTP (un)compressing data in the "deflate" compression format.static final intA constant used to indicate the file(s) being transferred should be treated as EBCDIC.static final intA constant used to indicate a file is to be treated as a continuous sequence of bytes.static final intA constant used to indicate the file(s) being transferred should be treated as a local type.static final intA constant used for text files to indicate a non-print text format.static final intA constant used to indicate a file is to be treated as a set of independent indexed pages.static final intA constant used to indicate a file is to be treated as a sequence of records.static final intLength of the FTP reply code (3 alphanumerics)static final intA constant used to indicate a file is to be transferred as a stream of bytes.protected booleanThis 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 RFC 959 for details.static final intA constant used to indicate a text file contains format vertical format control characters.Fields inherited from class org.apache.commons.net.SocketClient_defaultPort_, _hostname_, _input_, _output_, _serverSocketFactory_, _socket_, _socketFactory_, _timeout_, connectTimeout, NETASCII_EOL, remoteInetSocketAddress
- 
Constructor SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptionprotected voidGets the reply, but don't pass it to command listeners.protected void__noop()Send a noop and get the reply without reporting to the command listener.protected voidInitiates control connections and gets initial reply.protected void_connectAction_(Reader socketIsReader) Initiates control connections and gets initial reply.intabor()A convenience method to send the FTP ABOR command to the server, receive the reply, and return the reply code.intA convenience method to send the FTP ACCT command to the server, receive the reply, and return the reply code.intallo(int bytes) A convenience method to send the FTP ALLO command to the server, receive the reply, and return the reply code.intallo(int bytes, int recordSize) A convenience method to send the FTP ALLO command to the server, receive the reply, and return the reply code.intallo(long bytes) A convenience method to send the FTP ALLO command to the server, receive the reply, and return the reply code.intallo(long bytes, int recordSize) A convenience method to send the FTP ALLO command to the server, receive the reply, and return the reply code.intA convenience method to send the FTP APPE command to the server, receive the reply, and return the reply code.intcdup()A convenience method to send the FTP CDUP command to the server, receive the reply, and return the reply code.intA convenience method to send the FTP CWD command to the server, receive the reply, and return the reply code.intA convenience method to send the FTP DELE command to the server, receive the reply, and return the reply code.voidCloses 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.inteprt(InetAddress host, int port) A convenience method to send the FTP EPRT command to the server, receive the reply, and return the reply code.intepsv()A convenience method to send the FTP EPSV command to the server, receive the reply, and return the reply code.intfeat()A convenience method to send the FTP FEAT command to the server, receive the reply, and return the reply code.protected ProtocolCommandSupportProvide command support to super-classintgetReply()Fetches a reply from the FTP server and returns the integer reply code.intReturns the integer value of the reply code of the last FTP reply.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.inthelp()A convenience method to send the FTP HELP command to the server, receive the reply, and return the reply code.intA convenience method to send the FTP HELP command to the server, receive the reply, and return the reply code.booleanReturn whether strict multiline parsing is enabled, as per RFC 959, section 4.2.booleanReturn whether strict non-multiline parsing is enabled, as per RFC 959, section 4.2.intlist()A convenience method to send the FTP LIST command to the server, receive the reply, and return the reply code.intA convenience method to send the FTP LIST command to the server, receive the reply, and return the reply code.intSends the MDTM command for the given file.intA convenience method to send the FTP MFMT command to the server, receive the reply, and return the reply code.intA convenience method to send the FTP MKD command to the server, receive the reply, and return the reply code.intmlsd()A convenience method to send the FTP MLSD command to the server, receive the reply, and return the reply code.intA convenience method to send the FTP MLSD command to the server, receive the reply, and return the reply code.intmlst()A convenience method to send the FTP MLST command to the server, receive the reply, and return the reply code.intA convenience method to send the FTP MLST command to the server, receive the reply, and return the reply code.intmode(int mode) A convenience method to send the FTP MODE command to the server, receive the reply, and return the reply code.intnlst()A convenience method to send the FTP NLST command to the server, receive the reply, and return the reply code.intA convenience method to send the FTP NLST command to the server, receive the reply, and return the reply code.intnoop()A convenience method to send the FTP NOOP command to the server, receive the reply, and return the reply code.intA convenience method to send the FTP PASS command to the server, receive the reply, and return the reply code.intpasv()A convenience method to send the FTP PASV command to the server, receive the reply, and return the reply code.intport(InetAddress host, int port) A convenience method to send the FTP PORT command to the server, receive the reply, and return the reply code.intpwd()A convenience method to send the FTP PWD command to the server, receive the reply, and return the reply code.intquit()A convenience method to send the FTP QUIT command to the server, receive the reply, and return the reply code.intrein()A convenience method to send the FTP REIN command to the server, receive the reply, and return the reply code.intA convenience method to send the FTP REST command to the server, receive the reply, and return the reply code.intA convenience method to send the FTP RETR command to the server, receive the reply, and return the reply code.intA convenience method to send the FTP RMD command to the server, receive the reply, and return the reply code.intA convenience method to send the FTP RNFR command to the server, receive the reply, and return the reply code.intA convenience method to send the FTP RNTO command to the server, receive the reply, and return the reply code.intsendCommand(int command) Sends an FTP command with no arguments to the server, waits for a reply and returns the numerical response code.intsendCommand(int command, String args) Deprecated.intsendCommand(String command) Sends an FTP command with no arguments to the server, waits for a reply and returns the numerical response code.intsendCommand(String command, String args) Sends an FTP command to the server, waits for a reply and returns the numerical response code.intsendCommand(FTPCmd command) Sends an FTP command to the server, waits for a reply and returns the numerical response code.intsendCommand(FTPCmd command, String args) Sends an FTP command to the server, waits for a reply and returns the numerical response code.voidsetControlEncoding(String encoding) Saves the character encoding to be used by the FTP control connection.voidsetStrictMultilineParsing(boolean strictMultilineParsing) Sets strict multiline parsing.voidsetStrictReplyParsing(boolean strictReplyParsing) Sets strict non-multiline parsing.intA convenience method to send the FTP SITE command to the server, receive the reply, and return the reply code.intA convenience method to send the FTP SIZE command to the server, receive the reply, and return the reply code.intA convenience method to send the FTP SMNT command to the server, receive the reply, and return the reply code.intstat()A convenience method to send the FTP STAT command to the server, receive the reply, and return the reply code.intA convenience method to send the FTP STAT command to the server, receive the reply, and return the reply code.intA convenience method to send the FTP STOR command to the server, receive the reply, and return the reply code.intstou()A convenience method to send the FTP STOU command to the server, receive the reply, and return the reply code.intA convenience method to send the FTP STOU command to the server, receive the reply, and return the reply code.intstru(int structure) A convenience method to send the FTP STRU command to the server, receive the reply, and return the reply code.intsyst()A convenience method to send the FTP SYST command to the server, receive the reply, and return the reply code.inttype(int fileType) A convenience method to send the FTP TYPE command to the server, receive the reply, and return the reply code.inttype(int fileType, int formatOrByteSize) A convenience method to send the FTP TYPE command for text files to the server, receive the reply, and return the reply code.intA convenience method to send the FTP USER command to the server, receive the reply, and return the reply code.Methods inherited from class org.apache.commons.net.SocketClientaddProtocolCommandListener, applySocketAttributes, checkOpenOutputStream, connect, connect, connect, connect, connect, connect, createCommandSupport, fireCommandSent, fireReplyReceived, getCharset, getCharsetName, getConnectTimeout, getDefaultPort, getDefaultTimeout, getKeepAlive, getLocalAddress, getLocalPort, getProxy, getReceiveBufferSize, getRemoteAddress, getRemoteInetSocketAddress, getRemotePort, getSendBufferSize, getServerSocketFactory, getSoLinger, getSoTimeout, getTcpNoDelay, isAvailable, isConnected, removeProtocolCommandListener, setCharset, setConnectTimeout, setDefaultPort, setDefaultTimeout, setKeepAlive, setProxy, setReceiveBufferSize, setSendBufferSize, setServerSocketFactory, setSocketFactory, setSoLinger, setSoTimeout, setTcpNoDelay, verifyRemote
- 
Field Details- 
DEFAULT_DATA_PORTThe default FTP data port (20).- See Also:
 
- 
DEFAULT_PORTThe default FTP control port (21).- See Also:
 
- 
ASCII_FILE_TYPEA constant used to indicate the file(s) being transferred should be treated as ASCII. This is the default file type. All constants ending inFILE_TYPEare used to indicate file types.- See Also:
 
- 
EBCDIC_FILE_TYPEA constant used to indicate the file(s) being transferred should be treated as EBCDIC. Note however that there are several EBCDIC formats. All constants ending inFILE_TYPEare used to indicate file types.- See Also:
 
- 
BINARY_FILE_TYPEA constant used to indicate the file(s) being transferred should be treated as a binary image, i.e., no translations should be performed. All constants ending inFILE_TYPEare used to indicate file types.- See Also:
 
- 
LOCAL_FILE_TYPEA constant used to indicate the file(s) being transferred should be treated as a local type. All constants ending inFILE_TYPEare used to indicate file types.- See Also:
 
- 
NON_PRINT_TEXT_FORMATA constant used for text files to indicate a non-print text format. This is the default format. All constants ending inTEXT_FORMATare used to indicate text formatting for text transfers (both ASCII and EBCDIC).- See Also:
 
- 
TELNET_TEXT_FORMATA constant used to indicate a text file contains format vertical format control characters. All constants ending inTEXT_FORMATare used to indicate text formatting for text transfers (both ASCII and EBCDIC).- See Also:
 
- 
CARRIAGE_CONTROL_TEXT_FORMATA constant used to indicate a text file contains ASA vertical format control characters. All constants ending inTEXT_FORMATare used to indicate text formatting for text transfers (both ASCII and EBCDIC).- See Also:
 
- 
FILE_STRUCTUREA 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_STRUCTUREare used to indicate file structure for file transfers.- See Also:
 
- 
RECORD_STRUCTUREA constant used to indicate a file is to be treated as a sequence of records. All constants ending in_STRUCTUREare used to indicate file structure for file transfers.- See Also:
 
- 
PAGE_STRUCTUREA constant used to indicate a file is to be treated as a set of independent indexed pages. All constants ending in_STRUCTUREare used to indicate file structure for file transfers.- See Also:
 
- 
STREAM_TRANSFER_MODEA constant used to indicate a file is to be transferred as a stream of bytes. This is the default transfer mode. All constants ending inTRANSFER_MODEare used to indicate file transfer modes.- See Also:
 
- 
BLOCK_TRANSFER_MODEA constant used to indicate a file is to be transferred as a series of blocks. All constants ending inTRANSFER_MODEare used to indicate file transfer modes.- See Also:
 
- 
COMPRESSED_TRANSFER_MODEA constant used to indicate a file is to be transferred as FTP compressed data. All constants ending inTRANSFER_MODEare used to indicate file transfer modes. Currently unused.- See Also:
 
- 
DEFLATE_TRANSFER_MODEA constant used to indicate a file is to be transferred as FTP (un)compressing data in the "deflate" compression format. All constants ending inTRANSFER_MODEare used to indicate file transfer modes. See the Internet Draft Deflate transmission mode for FTP- See Also:
 
- 
DEFAULT_CONTROL_ENCODINGThe 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 withsetControlEncoding.
- 
REPLY_CODE_LENLength of the FTP reply code (3 alphanumerics)- See Also:
 
- 
_replyCode
- 
_replyLines
- 
_newReplyString
- 
_replyString
- 
_controlEncoding
- 
_commandSupport_A ProtocolCommandSupport object used to manage the registering of ProtocolCommandListeners and the firing of ProtocolCommandEvents.
- 
strictMultilineParsingThis 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 RFC 959 for details.
- 
_controlInput_Wraps SocketClient._input_ to facilitate the reading of text from 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 indisconnect().
- 
_controlOutput_Wraps SocketClient._output_ to facilitate the writing of text to 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 indisconnect().
 
- 
- 
Constructor Details- 
FTPpublic FTP()The default FTP constructor. Sets the default port toDEFAULT_PORTand initializes internal data structures for saving FTP reply information.
 
- 
- 
Method Details- 
__getReplyNoReportGets the reply, but don't pass it to command listeners. Used for keep-alive processing only.- Throws:
- IOException- on error
- Since:
- 3.0
 
- 
__noopSend a noop and get the reply without reporting to the command listener. Intended for use with keep-alive.- Throws:
- IOException- on error
- Since:
- 3.0
 
- 
_connectAction_Initiates control connections and gets initial reply. Initializes_controlInput_and_controlOutput_.- Overrides:
- _connectAction_in class- SocketClient
- Throws:
- IOException- (SocketException) if a problem occurs with the socket
 
- 
_connectAction_Initiates control connections and gets initial reply. Initializes_controlInput_and_controlOutput_.- Parameters:
- socketIsReader- the reader to reuse (if non-null)
- Throws:
- IOException- on error
- Since:
- 3.4
 
- 
aborA convenience method to send the FTP ABOR command to the server, receive the reply, and return the reply code.- Returns:
- The reply code received from the server.
- Throws:
- FTPConnectionClosedException- If the FTP server prematurely closes the connection as a result of the client being idle or some other reason causing the server to send FTP reply code 421. This exception may be caught either as an IOException or independently as itself.
- IOException- If an I/O error occurs while either sending the command or receiving the server reply.
 
- 
acctA convenience method to send the FTP ACCT command to the server, receive the reply, and return the reply code.- Parameters:
- account- The account name to access.
- Returns:
- The reply code received from the server.
- Throws:
- FTPConnectionClosedException- If the FTP server prematurely closes the connection as a result of the client being idle or some other reason causing the server to send FTP reply code 421. This exception may be caught either as an IOException or independently as itself.
- IOException- If an I/O error occurs while either sending the command or receiving the server reply.
 
- 
alloA convenience method to send the FTP ALLO command to the server, receive the reply, and return the reply code.- Parameters:
- bytes- The number of bytes to allocate.
- Returns:
- The reply code received from the server.
- Throws:
- FTPConnectionClosedException- If the FTP server prematurely closes the connection as a result of the client being idle or some other reason causing the server to send FTP reply code 421. This exception may be caught either as an IOException or independently as itself.
- IOException- If an I/O error occurs while either sending the command or receiving the server reply.
 
- 
alloA convenience method to send the FTP ALLO command to the server, receive the reply, and return the reply code.- Parameters:
- bytes- The number of bytes to allocate.
- recordSize- The size of a record.
- Returns:
- The reply code received from the server.
- Throws:
- FTPConnectionClosedException- If the FTP server prematurely closes the connection as a result of the client being idle or some other reason causing the server to send FTP reply code 421. This exception may be caught either as an IOException or independently as itself.
- IOException- If an I/O error occurs while either sending the command or receiving the server reply.
 
- 
alloA convenience method to send the FTP ALLO command to the server, receive the reply, and return the reply code.- Parameters:
- bytes- The number of bytes to allocate.
- Returns:
- The reply code received from the server.
- Throws:
- FTPConnectionClosedException- If the FTP server prematurely closes the connection as a result of the client being idle or some other reason causing the server to send FTP reply code 421. This exception may be caught either as an IOException or independently as itself.
- IOException- If an I/O error occurs while either sending the command or receiving the server reply.
 
- 
alloA convenience method to send the FTP ALLO command to the server, receive the reply, and return the reply code.- Parameters:
- bytes- The number of bytes to allocate.
- recordSize- The size of a record.
- Returns:
- The reply code received from the server.
- Throws:
- FTPConnectionClosedException- If the FTP server prematurely closes the connection as a result of the client being idle or some other reason causing the server to send FTP reply code 421. This exception may be caught either as an IOException or independently as itself.
- IOException- If an I/O error occurs while either sending the command or receiving the server reply.
 
- 
appeA 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, useFTPClient, which will handle all low level details for you.- Parameters:
- pathname- The pathname to use for the file when stored at the remote end of the transfer.
- Returns:
- The reply code received from the server.
- Throws:
- FTPConnectionClosedException- If the FTP server prematurely closes the connection as a result of the client being idle or some other reason causing the server to send FTP reply code 421. This exception may be caught either as an IOException or independently as itself.
- IOException- If an I/O error occurs while either sending the command or receiving the server reply.
 
- 
cdupA convenience method to send the FTP CDUP command to the server, receive the reply, and return the reply code.- Returns:
- The reply code received from the server.
- Throws:
- FTPConnectionClosedException- If the FTP server prematurely closes the connection as a result of the client being idle or some other reason causing the server to send FTP reply code 421. This exception may be caught either as an IOException or independently as itself.
- IOException- If an I/O error occurs while either sending the command or receiving the server reply.
 
- 
cwdA convenience method to send the FTP CWD command to the server, receive the reply, and return the reply code.- Parameters:
- directory- The new working directory.
- Returns:
- The reply code received from the server.
- Throws:
- FTPConnectionClosedException- If the FTP server prematurely closes the connection as a result of the client being idle or some other reason causing the server to send FTP reply code 421. This exception may be caught either as an IOException or independently as itself.
- IOException- If an I/O error occurs while either sending the command or receiving the server reply.
 
- 
deleA convenience method to send the FTP DELE command to the server, receive the reply, and return the reply code.- Parameters:
- pathname- The pathname to delete.
- Returns:
- The reply code received from the server.
- Throws:
- FTPConnectionClosedException- If the FTP server prematurely closes the connection as a result of the client being idle or some other reason causing the server to send FTP reply code 421. This exception may be caught either as an IOException or independently as itself.
- IOException- If an I/O error occurs while either sending the command or receiving the server reply.
 
- 
disconnectCloses 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.- Overrides:
- disconnectin class- SocketClient
- Throws:
- IOException- If an error occurs while disconnecting.
 
- 
eprtA convenience method to send the FTP EPRT command to the server, receive the reply, and return the reply code. Examples:- EPRT |1|132.235.1.2|6275|
- EPRT |2|1080::8:800:200C:417A|5282|
 - Parameters:
- host- The host owning the port.
- port- The new port.
- Returns:
- The reply code received from the server.
- Throws:
- FTPConnectionClosedException- If the FTP server prematurely closes the connection as a result of the client being idle or some other reason causing the server to send FTP reply code 421. This exception may be caught either as an IOException or independently as itself.
- IOException- If an I/O error occurs while either sending the command or receiving the server reply.
- Since:
- 2.2
- See Also:
 
- 
epsvA convenience method to send the FTP EPSV 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.- Returns:
- The reply code received from the server.
- Throws:
- FTPConnectionClosedException- If the FTP server prematurely closes the connection as a result of the client being idle or some other reason causing the server to send FTP reply code 421. This exception may be caught either as an IOException or independently as itself.
- IOException- If an I/O error occurs while either sending the command or receiving the server reply.
- Since:
- 2.2
 
- 
featA convenience method to send the FTP FEAT command to the server, receive the reply, and return the reply code.- Returns:
- The reply code received by the server
- Throws:
- IOException- If an I/O error occurs while either sending the command or receiving the server reply.
- Since:
- 2.2
 
- 
getCommandSupportProvide command support to super-class- Overrides:
- getCommandSupportin class- SocketClient
- Returns:
- the CommandSupport instance, may be null
 
- 
getControlEncoding- Returns:
- The character encoding used to communicate over the control connection.
 
- 
getReplyFetches 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 callinggetReplyStringorgetReplyStrings. 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.- Returns:
- The integer value of the reply code of the fetched FTP reply.
- Throws:
- FTPConnectionClosedException- If the FTP server prematurely closes the connection as a result of the client being idle or some other reason causing the server to send FTP reply code 421. This exception may be caught either as an IOException or independently as itself.
- IOException- If an I/O error occurs while receiving the server reply.
 
- 
getReplyCodeReturns 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 sinceconnectis of type void.- Returns:
- The integer value of the reply code of the last FTP reply.
 
- 
getReplyStringReturns the entire text of the last FTP server response exactly as it was received, including all end of line markers in NETASCII format.- Returns:
- The entire text from the last FTP response as a String.
 
- 
getReplyStringsReturns 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.- Returns:
- The lines of text from the last FTP response as an array.
 
- 
helpA convenience method to send the FTP HELP command to the server, receive the reply, and return the reply code.- Returns:
- The reply code received from the server.
- Throws:
- FTPConnectionClosedException- If the FTP server prematurely closes the connection as a result of the client being idle or some other reason causing the server to send FTP reply code 421. This exception may be caught either as an IOException or independently as itself.
- IOException- If an I/O error occurs while either sending the command or receiving the server reply.
 
- 
helpA convenience method to send the FTP HELP command to the server, receive the reply, and return the reply code.- Parameters:
- command- The command name on which to request help.
- Returns:
- The reply code received from the server.
- Throws:
- FTPConnectionClosedException- If the FTP server prematurely closes the connection as a result of the client being idle or some other reason causing the server to send FTP reply code 421. This exception may be caught either as an IOException or independently as itself.
- IOException- If an I/O error occurs while either sending the command or receiving the server reply.
 
- 
isStrictMultilineParsingReturn whether strict multiline parsing is enabled, as per RFC 959, section 4.2.- Returns:
- True if strict, false if lenient
- Since:
- 2.0
 
- 
isStrictReplyParsingReturn whether strict non-multiline parsing is enabled, as per RFC 959, section 4.2.The default is true, which requires the 3-digit code be followed by space and some text. 
 If false, only the 3-digit code is required (as was the case for versions up to 3.5)- Returns:
- True if strict (default), false if additional checks are not made
- Since:
- 3.6
 
- 
listA 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, useFTPClient, which will handle all low level details for you.- Returns:
- The reply code received from the server.
- Throws:
- FTPConnectionClosedException- If the FTP server prematurely closes the connection as a result of the client being idle or some other reason causing the server to send FTP reply code 421. This exception may be caught either as an IOException or independently as itself.
- IOException- If an I/O error occurs while either sending the command or receiving the server reply.
 
- 
listA 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, useFTPClient, which will handle all low level details for you.- Parameters:
- pathname- The pathname to list, may be- nullin which case the command is sent with no parameters
- Returns:
- The reply code received from the server.
- Throws:
- FTPConnectionClosedException- If the FTP server prematurely closes the connection as a result of the client being idle or some other reason causing the server to send FTP reply code 421. This exception may be caught either as an IOException or independently as itself.
- IOException- If an I/O error occurs while either sending the command or receiving the server reply.
 
- 
mdtmSends the MDTM command for the given file.- Parameters:
- file- name of file
- Returns:
- the status
- Throws:
- IOException- on error
- Since:
- 2.0
 
- 
mfmtA convenience method to send the FTP MFMT command to the server, receive the reply, and return the reply code.- Parameters:
- pathname- The pathname for which mtime is to be changed
- timeval- Timestamp in- yyyyMMDDhhmmssformat
- Returns:
- The reply code received from the server.
- Throws:
- FTPConnectionClosedException- If the FTP server prematurely closes the connection as a result of the client being idle or some other reason causing the server to send FTP reply code 421. This exception may be caught either as an IOException or independently as itself.
- IOException- If an I/O error occurs while either sending the command or receiving the server reply.
- Since:
- 2.2
- See Also:
 
- 
mkdA convenience method to send the FTP MKD command to the server, receive the reply, and return the reply code.- Parameters:
- pathname- The pathname of the new directory to create.
- Returns:
- The reply code received from the server.
- Throws:
- FTPConnectionClosedException- If the FTP server prematurely closes the connection as a result of the client being idle or some other reason causing the server to send FTP reply code 421. This exception may be caught either as an IOException or independently as itself.
- IOException- If an I/O error occurs while either sending the command or receiving the server reply.
 
- 
mlsdA convenience method to send the FTP MLSD 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, useFTPClient, which will handle all low level details for you.- Returns:
- The reply code received from the server.
- Throws:
- FTPConnectionClosedException- If the FTP server prematurely closes the connection as a result of the client being idle or some other reason causing the server to send FTP reply code 421. This exception may be caught either as an IOException or independently as itself.
- IOException- If an I/O error occurs while either sending the command or receiving the server reply.
- Since:
- 3.0
 
- 
mlsdA convenience method to send the FTP MLSD 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, useFTPClient, which will handle all low level details for you.- Parameters:
- path- the path to report on
- Returns:
- The reply code received from the server, may be nullin which case the command is sent with no parameters
- Throws:
- FTPConnectionClosedException- If the FTP server prematurely closes the connection as a result of the client being idle or some other reason causing the server to send FTP reply code 421. This exception may be caught either as an IOException or independently as itself.
- IOException- If an I/O error occurs while either sending the command or receiving the server reply.
- Since:
- 3.0
 
- 
mlstA convenience method to send the FTP MLST 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, useFTPClient, which will handle all low level details for you.- Returns:
- The reply code received from the server.
- Throws:
- FTPConnectionClosedException- If the FTP server prematurely closes the connection as a result of the client being idle or some other reason causing the server to send FTP reply code 421. This exception may be caught either as an IOException or independently as itself.
- IOException- If an I/O error occurs while either sending the command or receiving the server reply.
- Since:
- 3.0
 
- 
mlstA convenience method to send the FTP MLST 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, useFTPClient, which will handle all low level details for you.- Parameters:
- path- the path to report on
- Returns:
- The reply code received from the server, may be nullin which case the command is sent with no parameters
- Throws:
- FTPConnectionClosedException- If the FTP server prematurely closes the connection as a result of the client being idle or some other reason causing the server to send FTP reply code 421. This exception may be caught either as an IOException or independently as itself.
- IOException- If an I/O error occurs while either sending the command or receiving the server reply.
- Since:
- 3.0
 
- 
modeA convenience method to send the FTP MODE command to the server, receive the reply, and return the reply code.- Parameters:
- mode- The transfer mode to use (one of the- TRANSFER_MODEconstants).
- Returns:
- The reply code received from the server.
- Throws:
- FTPConnectionClosedException- If the FTP server prematurely closes the connection as a result of the client being idle or some other reason causing the server to send FTP reply code 421. This exception may be caught either as an IOException or independently as itself.
- IOException- If an I/O error occurs while either sending the command or receiving the server reply.
 
- 
nlstA 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, useFTPClient, which will handle all low level details for you.- Returns:
- The reply code received from the server.
- Throws:
- FTPConnectionClosedException- If the FTP server prematurely closes the connection as a result of the client being idle or some other reason causing the server to send FTP reply code 421. This exception may be caught either as an IOException or independently as itself.
- IOException- If an I/O error occurs while either sending the command or receiving the server reply.
 
- 
nlstA 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, useFTPClient, which will handle all low level details for you.- Parameters:
- pathname- The pathname to list, may be- nullin which case the command is sent with no parameters
- Returns:
- The reply code received from the server.
- Throws:
- FTPConnectionClosedException- If the FTP server prematurely closes the connection as a result of the client being idle or some other reason causing the server to send FTP reply code 421. This exception may be caught either as an IOException or independently as itself.
- IOException- If an I/O error occurs while either sending the command or receiving the server reply.
 
- 
noopA convenience method to send the FTP NOOP command to the server, receive the reply, and return the reply code.- Returns:
- The reply code received from the server.
- Throws:
- FTPConnectionClosedException- If the FTP server prematurely closes the connection as a result of the client being idle or some other reason causing the server to send FTP reply code 421. This exception may be caught either as an IOException or independently as itself.
- IOException- If an I/O error occurs while either sending the command or receiving the server reply.
 
- 
passA convenience method to send the FTP PASS command to the server, receive the reply, and return the reply code.- Parameters:
- password- The plain text password of the user being logged into.
- Returns:
- The reply code received from the server.
- Throws:
- FTPConnectionClosedException- If the FTP server prematurely closes the connection as a result of the client being idle or some other reason causing the server to send FTP reply code 421. This exception may be caught either as an IOException or independently as itself.
- IOException- If an I/O error occurs while either sending the command or receiving the server reply.
 
- 
pasvA 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.- Returns:
- The reply code received from the server.
- Throws:
- FTPConnectionClosedException- If the FTP server prematurely closes the connection as a result of the client being idle or some other reason causing the server to send FTP reply code 421. This exception may be caught either as an IOException or independently as itself.
- IOException- If an I/O error occurs while either sending the command or receiving the server reply.
 
- 
portA convenience method to send the FTP PORT command to the server, receive the reply, and return the reply code.- Parameters:
- host- The host owning the port.
- port- The new port.
- Returns:
- The reply code received from the server.
- Throws:
- FTPConnectionClosedException- If the FTP server prematurely closes the connection as a result of the client being idle or some other reason causing the server to send FTP reply code 421. This exception may be caught either as an IOException or independently as itself.
- IOException- If an I/O error occurs while either sending the command or receiving the server reply.
 
- 
pwdA convenience method to send the FTP PWD command to the server, receive the reply, and return the reply code.- Returns:
- The reply code received from the server.
- Throws:
- FTPConnectionClosedException- If the FTP server prematurely closes the connection as a result of the client being idle or some other reason causing the server to send FTP reply code 421. This exception may be caught either as an IOException or independently as itself.
- IOException- If an I/O error occurs while either sending the command or receiving the server reply.
 
- 
quitA convenience method to send the FTP QUIT command to the server, receive the reply, and return the reply code.- Returns:
- The reply code received from the server.
- Throws:
- FTPConnectionClosedException- If the FTP server prematurely closes the connection as a result of the client being idle or some other reason causing the server to send FTP reply code 421. This exception may be caught either as an IOException or independently as itself.
- IOException- If an I/O error occurs while either sending the command or receiving the server reply.
 
- 
reinA convenience method to send the FTP REIN command to the server, receive the reply, and return the reply code.- Returns:
- The reply code received from the server.
- Throws:
- FTPConnectionClosedException- If the FTP server prematurely closes the connection as a result of the client being idle or some other reason causing the server to send FTP reply code 421. This exception may be caught either as an IOException or independently as itself.
- IOException- If an I/O error occurs while either sending the command or receiving the server reply.
 
- 
restA convenience method to send the FTP REST command to the server, receive the reply, and return the reply code.- Parameters:
- marker- The marker at which to restart a transfer.
- Returns:
- The reply code received from the server.
- Throws:
- FTPConnectionClosedException- If the FTP server prematurely closes the connection as a result of the client being idle or some other reason causing the server to send FTP reply code 421. This exception may be caught either as an IOException or independently as itself.
- IOException- If an I/O error occurs while either sending the command or receiving the server reply.
 
- 
retrA 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, useFTPClient, which will handle all low level details for you.- Parameters:
- pathname- The pathname of the file to retrieve.
- Returns:
- The reply code received from the server.
- Throws:
- FTPConnectionClosedException- If the FTP server prematurely closes the connection as a result of the client being idle or some other reason causing the server to send FTP reply code 421. This exception may be caught either as an IOException or independently as itself.
- IOException- If an I/O error occurs while either sending the command or receiving the server reply.
 
- 
rmdA convenience method to send the FTP RMD command to the server, receive the reply, and return the reply code.- Parameters:
- pathname- The pathname of the directory to remove.
- Returns:
- The reply code received from the server.
- Throws:
- FTPConnectionClosedException- If the FTP server prematurely closes the connection as a result of the client being idle or some other reason causing the server to send FTP reply code 421. This exception may be caught either as an IOException or independently as itself.
- IOException- If an I/O error occurs while either sending the command or receiving the server reply.
 
- 
rnfrA convenience method to send the FTP RNFR command to the server, receive the reply, and return the reply code.- Parameters:
- pathname- The pathname to rename from.
- Returns:
- The reply code received from the server.
- Throws:
- FTPConnectionClosedException- If the FTP server prematurely closes the connection as a result of the client being idle or some other reason causing the server to send FTP reply code 421. This exception may be caught either as an IOException or independently as itself.
- IOException- If an I/O error occurs while either sending the command or receiving the server reply.
 
- 
rntoA convenience method to send the FTP RNTO command to the server, receive the reply, and return the reply code.- Parameters:
- pathname- The pathname to rename to
- Returns:
- The reply code received from the server.
- Throws:
- FTPConnectionClosedException- If the FTP server prematurely closes the connection as a result of the client being idle or some other reason causing the server to send FTP reply code 421. This exception may be caught either as an IOException or independently as itself.
- IOException- If an I/O error occurs while either sending the command or receiving the server reply.
 
- 
sendCommandSends 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 callinggetReplyStringorgetReplyStrings.- Parameters:
- command- The FTPCmd enum corresponding to the FTP command to send.
- Returns:
- The integer value of the FTP reply code returned by the server in response to the command.
- Throws:
- FTPConnectionClosedException- If the FTP server prematurely closes the connection as a result of the client being idle or some other reason causing the server to send FTP reply code 421. This exception may be caught either as an IOException or independently as itself.
- IOException- If an I/O error occurs while either sending the command or receiving the server reply.
- Since:
- 3.3
 
- 
sendCommandSends 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 callinggetReplyStringorgetReplyStrings.- Parameters:
- command- The FTPCmd enum corresponding to the FTP command to send.
- args- The arguments to the FTP command. If this parameter is set to null, then the command is sent with no argument.
- Returns:
- The integer value of the FTP reply code returned by the server in response to the command.
- Throws:
- FTPConnectionClosedException- If the FTP server prematurely closes the connection as a result of the client being idle or some other reason causing the server to send FTP reply code 421. This exception may be caught either as an IOException or independently as itself.
- IOException- If an I/O error occurs while either sending the command or receiving the server reply.
- Since:
- 3.3
 
- 
sendCommandSends 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 callinggetReplyStringorgetReplyStrings.- Parameters:
- command- The FTPCommand constant corresponding to the FTP command to send.
- Returns:
- The integer value of the FTP reply code returned by the server in response to the command.
- Throws:
- FTPConnectionClosedException- If the FTP server prematurely closes the connection as a result of the client being idle or some other reason causing the server to send FTP reply code 421. This exception may be caught either as an IOException or independently as itself.
- IOException- If an I/O error occurs while either sending the command or receiving the server reply.
 
- 
sendCommandDeprecated.(3.3) UsesendCommand(FTPCmd, String)insteadSends 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 callinggetReplyStringorgetReplyStrings.- Parameters:
- command- The FTPCommand constant corresponding to the FTP command to send.
- args- The arguments to the FTP command. If this parameter is set to null, then the command is sent with no argument.
- Returns:
- The integer value of the FTP reply code returned by the server in response to the command.
- Throws:
- FTPConnectionClosedException- If the FTP server prematurely closes the connection as a result of the client being idle or some other reason causing the server to send FTP reply code 421. This exception may be caught either as an IOException or independently as itself.
- IOException- If an I/O error occurs while either sending the command or receiving the server reply.
 
- 
sendCommandSends 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 callinggetReplyStringorgetReplyStrings.- Parameters:
- command- The text representation of the FTP command to send.
- Returns:
- The integer value of the FTP reply code returned by the server in response to the command.
- Throws:
- FTPConnectionClosedException- If the FTP server prematurely closes the connection as a result of the client being idle or some other reason causing the server to send FTP reply code 421. This exception may be caught either as an IOException or independently as itself.
- IOException- If an I/O error occurs while either sending the command or receiving the server reply.
 
- 
sendCommandSends 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 callinggetReplyStringorgetReplyStrings.- Parameters:
- command- The text representation of the FTP command to send.
- args- The arguments to the FTP command. If this parameter is set to null, then the command is sent with no argument.
- Returns:
- The integer value of the FTP reply code returned by the server in response to the command.
- Throws:
- FTPConnectionClosedException- If the FTP server prematurely closes the connection as a result of the client being idle or some other reason causing the server to send FTP reply code 421. This exception may be caught either as an IOException or independently as itself.
- IOException- If an I/O error occurs while either sending the command or receiving the server reply.
 
- 
setControlEncodingSaves the character encoding to be used by the FTP control connection. Some FTP servers require that commands be issued in a non-ASCII encoding like UTF-8 so that file names with multi-byte character representations (e.g, Big 8) can be specified.Please note that this has to be set before the connection is established. - Parameters:
- encoding- The new character encoding for the control connection.
 
- 
setStrictMultilineParsingSets strict multiline parsing.- Parameters:
- strictMultilineParsing- the setting
- Since:
- 2.0
 
- 
setStrictReplyParsingSets strict non-multiline parsing.If true, it requires the 3-digit code be followed by space and some text. 
 If false, only the 3-digit code is required (as was the case for versions up to 3.5)This should not be required by a well-behaved FTP server - Parameters:
- strictReplyParsing- the setting
- Since:
- 3.6
 
- 
siteA convenience method to send the FTP SITE command to the server, receive the reply, and return the reply code.- Parameters:
- parameters- The site parameters to send.
- Returns:
- The reply code received from the server.
- Throws:
- FTPConnectionClosedException- If the FTP server prematurely closes the connection as a result of the client being idle or some other reason causing the server to send FTP reply code 421. This exception may be caught either as an IOException or independently as itself.
- IOException- If an I/O error occurs while either sending the command or receiving the server reply.
 
- 
sizeA convenience method to send the FTP SIZE command to the server, receive the reply, and return the reply code.- Parameters:
- parameters- The site parameters to send.
- Returns:
- The reply code received from the server.
- Throws:
- FTPConnectionClosedException- If the FTP server prematurely closes the connection as a result of the client being idle or some other reason causing the server to send FTP reply code 421. This exception may be caught either as an IOException or independently as itself.
- IOException- If an I/O error occurs while either sending the command or receiving the server reply.
- Since:
- 3.7
 
- 
smntA convenience method to send the FTP SMNT command to the server, receive the reply, and return the reply code.- Parameters:
- dir- The directory name.
- Returns:
- The reply code received from the server.
- Throws:
- FTPConnectionClosedException- If the FTP server prematurely closes the connection as a result of the client being idle or some other reason causing the server to send FTP reply code 421. This exception may be caught either as an IOException or independently as itself.
- IOException- If an I/O error occurs while either sending the command or receiving the server reply.
 
- 
statA convenience method to send the FTP STAT command to the server, receive the reply, and return the reply code.- Returns:
- The reply code received from the server.
- Throws:
- FTPConnectionClosedException- If the FTP server prematurely closes the connection as a result of the client being idle or some other reason causing the server to send FTP reply code 421. This exception may be caught either as an IOException or independently as itself.
- IOException- If an I/O error occurs while either sending the command or receiving the server reply.
 
- 
statA convenience method to send the FTP STAT command to the server, receive the reply, and return the reply code.- Parameters:
- pathname- A pathname to list.
- Returns:
- The reply code received from the server.
- Throws:
- FTPConnectionClosedException- If the FTP server prematurely closes the connection as a result of the client being idle or some other reason causing the server to send FTP reply code 421. This exception may be caught either as an IOException or independently as itself.
- IOException- If an I/O error occurs while either sending the command or receiving the server reply.
 
- 
storA 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, useFTPClient, which will handle all low level details for you.- Parameters:
- pathname- The pathname to use for the file when stored at the remote end of the transfer.
- Returns:
- The reply code received from the server.
- Throws:
- FTPConnectionClosedException- If the FTP server prematurely closes the connection as a result of the client being idle or some other reason causing the server to send FTP reply code 421. This exception may be caught either as an IOException or independently as itself.
- IOException- If an I/O error occurs while either sending the command or receiving the server reply.
 
- 
stouA 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, useFTPClient, which will handle all low level details for you.- Returns:
- The reply code received from the server.
- Throws:
- FTPConnectionClosedException- If the FTP server prematurely closes the connection as a result of the client being idle or some other reason causing the server to send FTP reply code 421. This exception may be caught either as an IOException or independently as itself.
- IOException- If an I/O error occurs while either sending the command or receiving the server reply.
 
- 
stouA 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, useFTPClient, which will handle all low level details for you.- Parameters:
- pathname- The base pathname to use for the file when stored at the remote end of the transfer. Some FTP servers require this.
- Returns:
- The reply code received from the server.
- Throws:
- FTPConnectionClosedException- If the FTP server prematurely closes the connection as a result of the client being idle or some other reason causing the server to send FTP reply code 421. This exception may be caught either as an IOException or independently as itself.
- IOException- If an I/O error occurs while either sending the command or receiving the server reply.
 
- 
struA convenience method to send the FTP STRU command to the server, receive the reply, and return the reply code.- Parameters:
- structure- The structure of the file (one of the- _STRUCTUREconstants).
- Returns:
- The reply code received from the server.
- Throws:
- FTPConnectionClosedException- If the FTP server prematurely closes the connection as a result of the client being idle or some other reason causing the server to send FTP reply code 421. This exception may be caught either as an IOException or independently as itself.
- IOException- If an I/O error occurs while either sending the command or receiving the server reply.
 
- 
systA convenience method to send the FTP SYST command to the server, receive the reply, and return the reply code.- Returns:
- The reply code received from the server.
- Throws:
- FTPConnectionClosedException- If the FTP server prematurely closes the connection as a result of the client being idle or some other reason causing the server to send FTP reply code 421. This exception may be caught either as an IOException or independently as itself.
- IOException- If an I/O error occurs while either sending the command or receiving the server reply.
 
- 
typeA convenience method to send the FTP TYPE command to the server, receive the reply, and return the reply code.- Parameters:
- fileType- The type of the file (one of the- FILE_TYPEconstants).
- Returns:
- The reply code received from the server.
- Throws:
- FTPConnectionClosedException- If the FTP server prematurely closes the connection as a result of the client being idle or some other reason causing the server to send FTP reply code 421. This exception may be caught either as an IOException or independently as itself.
- IOException- If an I/O error occurs while either sending the command or receiving the server reply.
 
- 
typeA convenience method to send the FTP TYPE command for text files to the server, receive the reply, and return the reply code.- Parameters:
- fileType- The type of the file (one of the- FILE_TYPEconstants).
- formatOrByteSize- The format of the file (one of the- _FORMATconstants). In the case of- LOCAL_FILE_TYPE, the byte size.
- Returns:
- The reply code received from the server.
- Throws:
- FTPConnectionClosedException- If the FTP server prematurely closes the connection as a result of the client being idle or some other reason causing the server to send FTP reply code 421. This exception may be caught either as an IOException or independently as itself.
- IOException- If an I/O error occurs while either sending the command or receiving the server reply.
 
- 
userA convenience method to send the FTP USER command to the server, receive the reply, and return the reply code.- Parameters:
- user- The user to login under.
- Returns:
- The reply code received from the server.
- Throws:
- FTPConnectionClosedException- If the FTP server prematurely closes the connection as a result of the client being idle or some other reason causing the server to send FTP reply code 421. This exception may be caught either as an IOException or independently as itself.
- IOException- If an I/O error occurs while either sending the command or receiving the server reply.
 
 
- 
sendCommand(FTPCmd, String)instead