org.apache.commons.net.telnet.Telnet
|
+--org.apache.commons.net.telnet.TelnetClient
|
+--org.apache.commons.net.ftp.FTP
|
+--org.apache.commons.net.ftp.FTPClient
FTP
FTPConnectionClosedException
FTPFileEntryParser
FTPFileEntryParserFactory
DefaultFTPFileEntryParserFactory
org.apache.commons.net.MalformedServerReplyException
static int | ACTIVE_LOCAL_DATA_CONNECTION_MODE A constant indicating the FTP session is expecting all transfers to occur between the client (local) and server and that the server should connect to the client's data port to initiate a data transfer. |
static int | ACTIVE_REMOTE_DATA_CONNECTION_MODE A constant indicating the FTP session is expecting all transfers to occur between two remote servers and that the server the client is connected to should connect to the other server's data port to initiate a data transfer. |
static int | PASSIVE_LOCAL_DATA_CONNECTION_MODE A constant indicating the FTP session is expecting all transfers to occur between the client (local) and server and that the server is in passive mode, requiring the client to connect to the server's data port to initiate a transfer. |
static int | PASSIVE_REMOTE_DATA_CONNECTION_MODE A constant indicating the FTP session is expecting all transfers to occur between two remote servers and that the server the client is connected to is in passive mode, requiring the other server to connect to the first server's data port to initiate a data transfer. |
Default FTPClient constructor. |
void | |
Socket | _openDataConnection_(int command, String arg) Establishes a data connection with the FTP server, returning a Socket for the connection if successful. |
boolean | abort() Abort a transfer in progress. |
boolean | allocate(int bytes) Reserve a number of bytes on the server for the next file transfer. |
boolean | allocate(int bytes, int recordSize) Reserve space on the server for the next file transfer. |
boolean | appendFile(String remote, InputStream local) Appends to a file on the server with the given name, taking input from the given InputStream. |
OutputStream | appendFileStream(String remote) Returns an OutputStream through which data can be written to append to a file on the server with the given name. |
boolean | Change to the parent directory of the current working directory. |
boolean | changeWorkingDirectory(String pathname) Change the current working directory of the FTP session. |
boolean | There are a few FTPClient methods that do not complete the entire sequence of FTP commands to complete a transaction. |
createFileList(FTPFileEntryParser parser) Using a programmer specified FTPFileEntryParser , initialize an object containing a raw file information for the current working directory. | |
createFileList(String pathname, FTPFileEntryParser parser) Using a programmer specified FTPFileEntryParser , initialize an object containing a raw file information for a directory or information for a single file. | |
boolean | deleteFile(String pathname) Deletes a file on the FTP server. |
void | Closes the connection to the FTP server and restores connection parameters to the default values. |
void | Set the current data connection mode to ACTIVE_LOCAL_DATA_CONNECTION_MODE. |
void | Set the current data connection mode to PASSIVE_LOCAL_DATA_CONNECTION_MODE . |
boolean | enterRemoteActiveMode(InetAddress host, int port) Set the current data connection mode to ACTIVE_REMOTE_DATA_CONNECTION . |
boolean | Set the current data connection mode to PASSIVE_REMOTE_DATA_CONNECTION_MODE . |
int | Returns the current data connection mode (one of the _DATA_CONNECTION_MODE constants. |
String | Returns the hostname or IP address (in the form of a string) returned by the server when entering passive mode. |
int | If in passive mode, returns the data port of the passive host. |
long | Fetches the restart offset. |
String | Issue the FTP STAT command to the server. |
String | getStatus(String pathname) Issue the FTP STAT command to the server for a given pathname. |
String | Fetches the system type name from the server and returns the string. |
Using the default autodetect mechanism, initialize an FTPListParseEngine object containing a raw file information for the current working directory on the server This information is obtained through the LIST command. | |
initiateListParsing(String pathname) Using the default autodetect mechanism, initialize an FTPListParseEngine object containing a raw file information for the supplied directory. | |
initiateListParsing(String parserKey, String pathname) Using the supplied parser key, initialize an FTPListParseEngine object containing a raw file information for the supplied directory. | |
boolean | Return whether or not verification of the remote host participating in data connections is enabled. |
FTPFile[] | listFiles(String parserKey, String pathname) Using the supplied parserKey, obtain a list of file information for the current working directory or for just a single file. |
FTPFile[] | listFiles(String pathname) Using the default system autodetect mechanism, obtain a list of file information for the current working directory or for just a single file. |
FTPFile[] | Using the default system autodetect mechanism, obtain a list of file information for the current working directory. |
FTPFile[] | listFiles(FTPFileListParser parser, String pathname) Using a programmer specified FTPFileListParser , obtain a list of file information for a directory or information for just a single file. |
FTPFile[] | listFiles(FTPFileListParser parser) Using a programmer specified FTPFileListParser , obtain a list of file information for the current working directory. |
String | listHelp() Fetches the system help information from the server and returns the full string. |
String | listHelp(String command) Fetches the help information for a given command from the server and returns the full string. |
String[] | listNames(String pathname) Obtain a list of filenames in a directory (or just the name of a given file, which is not particularly useful). |
String[] | Obtain a list of filenames in the current working directory This information is obtained through the NLST command. |
boolean | login(String username, String password) Login to the FTP server using the provided username and password. |
boolean | login(String username, String password, String account) Login to the FTP server using the provided username, password, and account. |
boolean | logout() Logout of the FTP server by sending the QUIT command. |
boolean | makeDirectory(String pathname) Creates a new subdirectory on the FTP server in the current directory (if a relative pathname is given) or where specified (if an absolute pathname is given). |
String | Returns the pathname of the current working directory. |
boolean | remoteAppend(String filename) Initiate a server to server file transfer. |
boolean | remoteRetrieve(String filename) Initiate a server to server file transfer. |
boolean | remoteStore(String filename) Initiate a server to server file transfer. |
boolean | remoteStoreUnique(String filename) Initiate a server to server file transfer. |
boolean | Initiate a server to server file transfer. |
boolean | removeDirectory(String pathname) Removes a directory on the FTP server (if empty). |
boolean | rename(String from, String to) Renames a remote file. |
boolean | retrieveFile(String remote, OutputStream local) Retrieves a named file from the server and writes it to the given OutputStream. |
InputStream | retrieveFileStream(String remote) Returns an InputStream from which a named file from the server can be read. |
boolean | sendNoOp() Sends a NOOP command to the FTP server. |
boolean | sendSiteCommand(String arguments) Send a site specific command. |
void | setDataTimeout(int timeout) Sets the timeout in milliseconds to use when reading from the data connection. |
boolean | setFileStructure(int structure) Sets the file structure. |
boolean | setFileTransferMode(int mode) Sets the transfer mode. |
boolean | setFileType(int fileType) Sets the file type to be transferred. |
boolean | setFileType(int fileType, int formatOrByteSize) Sets the file type to be transferred and the format. |
void | setParserFactory(FTPFileEntryParserFactory parserFactory) set the factory used for parser creation to the supplied factory object. |
void | setRemoteVerificationEnabled(boolean enable) Enable or disable verification that the remote host taking part of a data connection is the same as the host to which the control connection is attached. |
void | setRestartOffset(long offset) Sets the restart offset. |
boolean | storeFile(String remote, InputStream local) Stores a file on the server using the given name and taking input from the given InputStream. |
OutputStream | storeFileStream(String remote) Returns an OutputStream through which data can be written to store a file on the server using the given name. |
boolean | storeUniqueFile(String remote, InputStream local) Stores a file on the server using a unique name derived from the given name and taking input from the given InputStream. |
boolean | storeUniqueFile(InputStream local) Stores a file on the server using a unique name assigned by the server and taking input from the given InputStream. |
OutputStream | storeUniqueFileStream(String remote) Returns an OutputStream through which data can be written to store a file on the server using a unique name derived from the given name. |
OutputStream | Returns an OutputStream through which data can be written to store a file on the server using a unique name assigned by the server. |
boolean | structureMount(String pathname) Issue the FTP SMNT command. |
public static final int ACTIVE_LOCAL_DATA_CONNECTION_MODE
public static final int ACTIVE_REMOTE_DATA_CONNECTION_MODE
public static final int PASSIVE_LOCAL_DATA_CONNECTION_MODE
public static final int PASSIVE_REMOTE_DATA_CONNECTION_MODE
public FTPClient()
ACTIVE_LOCAL_DATA_CONNECTION_MODE , the file type
set to FTP.ASCII_FILE_TYPE , the
file format set to FTP.NON_PRINT_TEXT_FORMAT ,
the file structure set to FTP.FILE_STRUCTURE , and
the transfer mode set to FTP.STREAM_TRANSFER_MODE .
protected void _connectAction_()
protected Socket _openDataConnection_(int command, String arg)
- If an I/O error occurs while either sending a
command to the server or receiving a reply from the server.public boolean abort()
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. - If an I/O error occurs while either sending a
command to the server or receiving a reply from the server.public boolean allocate(int bytes)
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. - If an I/O error occurs while either sending a
command to the server or receiving a reply from the server.public boolean allocate(int bytes, int recordSize)
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. - If an I/O error occurs while either sending a
command to the server or receiving a reply from the server.public boolean appendFile(String remote, InputStream local)
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. - If an I/O error occurs while actually
transferring the file. - If an I/O error occurs while either sending a
command to the server or receiving a reply from the server.public OutputStream appendFileStream(String remote)
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. - If an I/O error occurs while either sending a
command to the server or receiving a reply from the server.public boolean changeToParentDirectory()
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. - If an I/O error occurs while either sending a
command to the server or receiving a reply from the server.public boolean changeWorkingDirectory(String pathname)
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. - If an I/O error occurs while either sending a
command to the server or receiving a reply from the server.public boolean completePendingCommand()
InputStream input;
OutputStream output;
input = new FileInputStream("foobaz.txt");
output = ftp.storeFileStream("foobar.txt")
if(!FTPReply.isPositiveIntermediate(ftp.getReplyCode())) {
input.close();
output.close();
ftp.logout();
ftp.disconnect();
System.err.println("File transfer failed.");
System.exit(1);
}
Util.copyStream(input, output);
input.close();
output.close();
// Must call completePendingCommand() to finish command.
if(!ftp.completePendingCommand()) {
ftp.logout();
ftp.disconnect();
System.err.println("File transfer failed.");
System.exit(1);
}
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. - If an I/O error occurs while either sending a
command to the server or receiving a reply from the server.public FTPFileList createFileList(String pathname, FTPFileEntryParser parser)
FTPFileEntryParser ,
initialize an object containing a raw file information for a directory
or information for a single file. This information is obtained through
the LIST command. This object is then capable of being iterated to
return a sequence of FTPFile objects with information filled in by the
FTPFileEntryParser used.
The server may or may not expand glob expressions. You should avoid
using glob expressions because the return format for glob listings
differs from server to server and will likely cause this method to fail.
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. - If an I/O error occurs while either sending a
command to the server or receiving a reply from the server.FTPFileList
public FTPFileList createFileList(FTPFileEntryParser parser)
FTPFileEntryParser ,
initialize an object containing a raw file information for the
current working directory. This information is obtained through
the LIST command. This object is then capable of being iterated to
return a sequence of FTPFile objects with information filled in by the
FTPFileEntryParser used.
The server may or may not expand glob expressions. You should avoid
using glob expressions because the return format for glob listings
differs from server to server and will likely cause this method to fail.
This method differs from using the listFiles() methods in that
expensive FTPFile objects are not created until needed which may be
an advantage on large lists.
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. - If an I/O error occurs while either sending a
command to the server or receiving a reply from the server.FTPFileList
public boolean deleteFile(String pathname)
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. - If an I/O error occurs while either sending a
command to the server or receiving a reply from the server.public void disconnect()
- If an error occurs while disconnecting.public void enterLocalActiveMode()
ACTIVE_LOCAL_DATA_CONNECTION_MODE. No communication
with the FTP server is conducted, but this causes all future data
transfers to require the FTP server to connect to the client's
data port. Additionally, to accommodate differences between socket
implementations on different platforms, this method causes the
client to issue a PORT command before every data transfer.
public void enterLocalPassiveMode()
PASSIVE_LOCAL_DATA_CONNECTION_MODE . Use this
method only for data transfers between the client and server.
This method causes a PASV command to be issued to the server
before the opening of every data connection, telling the server to
open a data port to which the client will connect to conduct
data transfers. The FTPClient will stay in
PASSIVE_LOCAL_DATA_CONNECTION_MODE until the
mode is changed by calling some other method such as
enterLocalActiveMode()
public boolean enterRemoteActiveMode(InetAddress host, int port)
ACTIVE_REMOTE_DATA_CONNECTION . Use this method only
for server to server data transfers. This method issues a PORT
command to the server, indicating the other server and port to which
it should connect for data transfers. You must call this method
before EVERY server to server transfer attempt. The FTPClient will
NOT automatically continue to issue PORT commands. You also
must remember to call
enterLocalActiveMode() if you
wish to return to the normal data connection mode.
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. - If an I/O error occurs while either sending a
command to the server or receiving a reply from the server.public boolean enterRemotePassiveMode()
PASSIVE_REMOTE_DATA_CONNECTION_MODE . Use this
method only for server to server data transfers.
This method issues a PASV command to the server, telling it to
open a data port to which the active server will connect to conduct
data transfers. You must call this method
before EVERY server to server transfer attempt. The FTPClient will
NOT automatically continue to issue PASV commands. You also
must remember to call
enterLocalActiveMode() if you
wish to return to the normal data connection mode.
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. - If an I/O error occurs while either sending a
command to the server or receiving a reply from the server.public int getDataConnectionMode()
_DATA_CONNECTION_MODE constants.
public String getPassiveHost()
public int getPassivePort()
public long getRestartOffset()
public String getStatus()
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. - If an I/O error occurs while either sending a
command to the server or receiving a reply from the server.public String getStatus(String pathname)
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. - If an I/O error occurs while either sending a
command to the server or receiving a reply from the server.public String getSystemName()
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. - If an I/O error occurs while either sending a
command to the server or receiving a reply from the server.public FTPListParseEngine initiateListParsing()
FTPFileEntryParser used.
This method differs from using the listFiles() methods in that
expensive FTPFile objects are not created until needed which may be
an advantage on large lists.
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. - If an I/O error occurs while either sending a
command to the server or receiving a reply from the server. - Thrown if the autodetect mechanism cannot
resolve the type of system we are connected with.FTPListParseEngine
public FTPListParseEngine initiateListParsing(String pathname)
FTPFileEntryParser used.
The server may or may not expand glob expressions. You should avoid
using glob expressions because the return format for glob listings
differs from server to server and will likely cause this method to fail.
This method differs from using the listFiles() methods in that
expensive FTPFile objects are not created until needed which may be
an advantage on large lists.
FTPClient f=FTPClient();
f.connect(server);
f.login(username, password);
FTPListParseEngine engine = f.initiateListParsing(directory);
while (engine.hasNext()) {
FTPFile[] files = engine.getNext(25); // "page size" you want
//do whatever you want with these files, display them, etc.
//expensive FTPFile objects not created until needed.
}
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. - If an I/O error occurs while either sending a
command to the server or receiving a reply from the server. - Thrown if the autodetect mechanism cannot
resolve the type of system we are connected with.FTPListParseEngine
public FTPListParseEngine initiateListParsing(String parserKey, String pathname)
FTPFileEntryParser used.
The server may or may not expand glob expressions. You should avoid
using glob expressions because the return format for glob listings
differs from server to server and will likely cause this method to fail.
This method differs from using the listFiles() methods in that
expensive FTPFile objects are not created until needed which may be
an advantage on large lists.
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. - If an I/O error occurs while either sending a
command to the server or receiving a reply from the server. - Thrown if the parserKey parameter cannot be
resolved by the selected parser factory.FTPListParseEngine
public boolean isRemoteVerificationEnabled()
public FTPFile[] listFiles()
FTPFileEntryParser
used.
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. - If an I/O error occurs while either sending a
command to the server or receiving a reply
from the server. - Thrown if the parserKey parameter cannot be
resolved by the selected parser factory.org.apache.commons.net.ftp.parser.DefaultFTPFileEntryParserFactory
org.apache.commons.net.ftp.parser.FTPFileEntryParserFactory
org.apache.commons.net.ftp.FTPFileEntryParser
public FTPFile[] listFiles(String pathname)
FTPFileEntryParser
used.
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. - If an I/O error occurs while either sending a
command to the server or receiving a reply
from the server. - Thrown if the parserKey parameter cannot be
resolved by the selected parser factory.org.apache.commons.net.ftp.parser.DefaultFTPFileEntryParserFactory
org.apache.commons.net.ftp.parser.FTPFileEntryParserFactory
org.apache.commons.net.ftp.FTPFileEntryParser
public FTPFile[] listFiles(String parserKey, String pathname)
parserKey, obtain a list
of file information for the current working directory or for just a
single file.
If key is null, this object will try to autodetect
the system-type/parser-type by calling the SYST command.
Under the DefaultFTPFileEntryParserFactory, which is used unless a
different factory has been specified, the key
can be either a recognized System type for which a parser has been
defined, or the fully qualified class name of a class that implements
org.apache.commons.net.ftp.FTPFileEntryParser.
This information is obtained through the LIST command. The contents of
the returned array is determined by the FTPFileEntryParser
used.
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. - If an I/O error occurs while either sending a
command to the server or receiving a reply
from the server. - Thrown if the parserKey parameter cannot be
resolved by the selected parser factory.org.apache.commons.net.ftp.parser.DefaultFTPFileEntryParserFactory
org.apache.commons.net.ftp.parser.FTPFileEntryParserFactory
org.apache.commons.net.ftp.FTPFileEntryParser
public FTPFile[] listFiles(FTPFileListParser parser)
FTPFileListParser ,
obtain a list of file information for the current working directory.
This information is obtained through the LIST command.
The contents of the array returned is determined by the
FTPFileListParser used.
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. - If an I/O error occurs while either sending a
command to the server or receiving a reply from the server. - public FTPFile[] listFiles(FTPFileListParser parser, String pathname)
FTPFileListParser , obtain a
list of file information for a directory or information for
just a single file. This information is obtained through the LIST
command. The contents of the returned array is determined by the
FTPFileListParser used.
The server may or may not expand glob expressions. You should avoid
using glob expressions because the return format for glob listings
differs from server to server and will likely cause this method to fail.
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. - If an I/O error occurs while either sending a
command to the server or receiving a reply from the server. - public String listHelp()
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. - If an I/O error occurs while either sending a
command to the server or receiving a reply from the server.public String listHelp(String command)
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. - If an I/O error occurs while either sending a
command to the server or receiving a reply from the server.public String[] listNames()
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. - If an I/O error occurs while either sending a
command to the server or receiving a reply from the server.public String[] listNames(String pathname)
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. - If an I/O error occurs while either sending a
command to the server or receiving a reply from the server.public boolean login(String username, String password)
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. - If an I/O error occurs while either sending a
command to the server or receiving a reply from the server.public boolean login(String username, String password, String account)
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. - If an I/O error occurs while either sending a
command to the server or receiving a reply from the server.public boolean logout()
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. - If an I/O error occurs while either sending a
command to the server or receiving a reply from the server.public boolean makeDirectory(String pathname)
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. - If an I/O error occurs while either sending a
command to the server or receiving a reply from the server.public String printWorkingDirectory()
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. - If an I/O error occurs while either sending a
command to the server or receiving a reply from the server.public boolean remoteAppend(String filename)
remoteRetrieve issued to it by another FTPClient.
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. - If an I/O error occurs while either sending a
command to the server or receiving a reply from the server.public boolean remoteRetrieve(String filename)
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. - If an I/O error occurs while either sending a
command to the server or receiving a reply from the server.public boolean remoteStore(String filename)
remoteRetrieve issued to it by another
FTPClient.
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. - If an I/O error occurs while either sending a
command to the server or receiving a reply from the server.public boolean remoteStoreUnique()
remoteRetrieve issued
to it by another FTPClient. Many FTP servers require that a base
filename be given from which the unique filename can be derived. For
those servers use the other version of remoteStoreUnique
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. - If an I/O error occurs while either sending a
command to the server or receiving a reply from the server.public boolean remoteStoreUnique(String filename)
remoteRetrieve issued
to it by another FTPClient.
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. - If an I/O error occurs while either sending a
command to the server or receiving a reply from the server.public boolean removeDirectory(String pathname)
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. - If an I/O error occurs while either sending a
command to the server or receiving a reply from the server.public boolean rename(String from, String to)
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. - If an I/O error occurs while either sending a
command to the server or receiving a reply from the server.public boolean retrieveFile(String remote, OutputStream local)
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. - If an I/O error occurs while actually
transferring the file. - If an I/O error occurs while either sending a
command to the server or receiving a reply from the server.public InputStream retrieveFileStream(String remote)
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. - If an I/O error occurs while either sending a
command to the server or receiving a reply from the server.public boolean sendNoOp()
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. - If an I/O error occurs while either sending a
command to the server or receiving a reply from the server.public boolean sendSiteCommand(String arguments)
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. - If an I/O error occurs while either sending a
command to the server or receiving a reply from the server.public void setDataTimeout(int timeout)
public boolean setFileStructure(int structure)
FTP.FILE_STRUCTURE if this method is never called.
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. - If an I/O error occurs while either sending a
command to the server or receiving a reply from the server.public boolean setFileTransferMode(int mode)
FTP.STREAM_TRANSFER_MODE if this method is never called.
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. - If an I/O error occurs while either sending a
command to the server or receiving a reply from the server.public boolean setFileType(int fileType)
FTP.ASCII_FILE_TYPE , FTP.IMAGE_FILE_TYPE ,
etc. The file type only needs to be set when you want to change the
type. After changing it, the new type stays in effect until you change
it again. The default file type is FTP.ASCII_FILE_TYPE
if this method is never called.
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. - If an I/O error occurs while either sending a
command to the server or receiving a reply from the server.public boolean setFileType(int fileType, int formatOrByteSize)
FTP.ASCII_FILE_TYPE ,
FTP.IMAGE_FILE_TYPE , etc. The file type only needs to
be set when you want to change the type. After changing it, the new
type stays in effect until you change it again. The default file type
is FTP.ASCII_FILE_TYPE if this method is never called.
The format should be one of the FTP class TEXT_FORMAT
constants, or if the type is FTP.LOCAL_FILE_TYPE , the
format should be the byte size for that type. The default format
is FTP.NON_PRINT_TEXT_FORMAT if this method is never
called.
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. - If an I/O error occurs while either sending a
command to the server or receiving a reply from the server.public void setParserFactory(FTPFileEntryParserFactory parserFactory)
org.apache.commons.net.ftp.parser.FTPFileEntryParserFactory
org.apache.commons.net.ftp.parser.DefaultFTPFileEntryParserFactory
public void setRemoteVerificationEnabled(boolean enable)
public void setRestartOffset(long offset)
public boolean storeFile(String remote, InputStream local)
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. - If an I/O error occurs while actually
transferring the file. - If an I/O error occurs while either sending a
command to the server or receiving a reply from the server.public OutputStream storeFileStream(String remote)
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. - If an I/O error occurs while either sending a
command to the server or receiving a reply from the server.public boolean storeUniqueFile(InputStream local)
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. - If an I/O error occurs while actually
transferring the file. - If an I/O error occurs while either sending a
command to the server or receiving a reply from the server.public boolean storeUniqueFile(String remote, InputStream local)
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. - If an I/O error occurs while actually
transferring the file. - If an I/O error occurs while either sending a
command to the server or receiving a reply from the server.public OutputStream storeUniqueFileStream()
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. - If an I/O error occurs while either sending a
command to the server or receiving a reply from the server.public OutputStream storeUniqueFileStream(String remote)
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. - If an I/O error occurs while either sending a
command to the server or receiving a reply from the server.public boolean structureMount(String pathname)
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. - If an I/O error occurs while either sending a
command to the server or receiving a reply from the server.
try { int reply; ftp.connect("ftp.foobar.com"); System.out.println("Connected to " + server + "."); System.out.print(ftp.getReplyString()); // After connection attempt, you should check the reply code to verify // success. reply = ftp.getReplyCode(); if(!FTPReply.isPositiveCompletion(reply)) { ftp.disconnect(); System.err.println("FTP server refused connection."); System.exit(1); } } catch(IOException e) { if(ftp.isConnected()) { try { ftp.disconnect(); } catch(IOException f) { // do nothing } } System.err.println("Could not connect to server."); e.printStackTrace(); System.exit(1); }Immediately after connecting is the only real time you need to check the reply code (because connect is of type void). The convention for all the FTP command methods in FTPClient is such that they either return a boolean value or some other value. The boolean methods return true on a successful completion reply from the FTP server and false on a reply resulting in an error condition or failure. The methods returning a value other than boolean return a value containing the higher level data produced by the FTP command, or null if a reply resulted in an error condition or failure. If you want to access the exact FTP reply code causing a success or failure, you must call getReplyCode after a success or failure. The default settings for FTPClient are for it to useFTP.ASCII_FILE_TYPE,FTP.NON_PRINT_TEXT_FORMAT,FTP.STREAM_TRANSFER_MODE, andFTP.FILE_STRUCTURE. The only file types directly supported areFTP.ASCII_FILE_TYPEandFTP.IMAGE_FILE_TYPE(which is the same asFTP.BINARY_FILE_TYPE). Because there are at lest 4 different EBCDIC encodings, we have opted not to provide direct support for EBCDIC. To transfer EBCDIC and other unsupported file types you must create your own filter InputStreams and OutputStreams and wrap them around the streams returned or required by the FTPClient methods. FTPClient uses the NetASCII filter streams in org.apache.commons.net.io to provide transparent handling of ASCII files. We will consider incorporating EBCDIC support if there is enough demand.FTP.NON_PRINT_TEXT_FORMAT,FTP.STREAM_TRANSFER_MODE, andFTP.FILE_STRUCTUREare the only supported formats, transfer modes, and file structures. Because the handling of sockets on different platforms can differ significantly, the FTPClient automatically issues a new PORT command prior to every transfer requiring that the server connect to the client's data port. This ensures identical problem-free behavior on Windows, Unix, and Macintosh platforms. Additionally, it relieves programmers from having to issue the PORT command themselves and dealing with platform dependent issues. Additionally, for security purposes, all data connections to the client are verified to ensure that they originated from the intended party (host and port). If a data connection is initiated by an unexpected party, the command will close the socket and throw an IOException. You may disable this behavior with setRemoteVerificationEnabled(). You should keep in mind that the FTP server may choose to prematurely close a connection if the client has been idle for longer than a given time period (usually 900 seconds). The FTPClient 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 .FTPConnectionClosedExceptionis a subclass ofIOExceptionand therefore need not be caught separately, but if you are going to catch it separately, its catch block must appear before the more generalIOExceptioncatch block. When you encounter an FTPConnectionClosedException , you must disconnect the connection with disconnect() to properly clean up the system resources used by FTPClient. 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. Listing API Examples Both paged and unpaged examples of directory listings are available, as follows: Unpaged (whole list) access, using a parser accessible by auto-detect:FTPClient f=FTPClient(); f.connect(server); f.login(username, password); FTPFile[] files = listFiles(directory);Paged access, using a parser not accessible by auto-detect. The class defined in the first parameter of initateListParsing should be derived from org.apache.commons.net.FTPFileEntryParser:FTPClient f=FTPClient(); f.connect(server); f.login(username, password); FTPListParseEngine engine = f.initiateListParsing("com.whatever.YourOwnParser", directory); while (engine.hasNext()) { FTPFile[] files = engine.getNext(25); // "page size" you want //do whatever you want with these files, display them, etc. //expensive FTPFile objects not created until needed. }Paged access, using a parser accessible by auto-detect:FTPClient f=FTPClient(); f.connect(server); f.login(username, password); FTPListParseEngine engine = f.initiateListParsing(directory); while (engine.hasNext()) { FTPFile[] files = engine.getNext(25); // "page size" you want //do whatever you want with these files, display them, etc. //expensive FTPFile objects not created until needed. }* @author Daniel F. Savarese