| org.apache.commons.net.ftp.FTP org.apache.commons.net.ftp.FTPClient
FTPClient | public class FTPClient extends FTP implements Configurable(Code) | | FTPClient encapsulates all the functionality necessary to store and
retrieve files from an FTP server. This class takes care of all
low level details of interacting with an FTP server and provides
a convenient higher level interface. As with all classes derived
from
org.apache.commons.net.SocketClient ,
you must first connect to the server with
org.apache.commons.net.SocketClient.connect connect before doing anything, and finally
org.apache.commons.net.SocketClient.disconnect disconnect after you're completely finished interacting with the server.
Then you need to check the FTP reply code to see if the connection
was successful. For example:
boolean error = false;
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);
}
... // transfer files
ftp.logout();
} catch(IOException e) {
error = true;
e.printStackTrace();
} finally {
if(ftp.isConnected()) {
try {
ftp.disconnect();
} catch(IOException ioe) {
// do nothing
}
}
System.exit(error ? 1 : 0);
}
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
org.apache.commons.net.ftp.FTP.getReplyCode getReplyCode after
a success or failure.
The default settings for FTPClient are for it to use
FTP.ASCII_FILE_TYPE ,
FTP.NON_PRINT_TEXT_FORMAT ,
FTP.STREAM_TRANSFER_MODE , and
FTP.FILE_STRUCTURE . The only file types directly supported
are FTP.ASCII_FILE_TYPE and
FTP.IMAGE_FILE_TYPE (which is the same as
FTP.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
ToNetASCIIOutputStream NetASCII
filter streams 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 , and
FTP.FILE_STRUCTURE are 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
FTPClient.setRemoteVerificationEnabled setRemoteVerificationEnabled() .
You should keep in mind that the FTP server may choose to prematurely
close a connection if the client has been idle for longer than a
given time period (usually 900 seconds). The FTPClient class will detect a
premature FTP server connection closing when it receives a
org.apache.commons.net.ftp.FTPReply.SERVICE_NOT_AVAILABLE FTPReply.SERVICE_NOT_AVAILABLE response to a command.
When that occurs, the FTP class method encountering that reply will throw
an
org.apache.commons.net.ftp.FTPConnectionClosedException .
FTPConnectionClosedException
is a subclass of IOException and therefore need not be
caught separately, but if you are going to catch it separately, its
catch block must appear before the more general IOException
catch block. When you encounter an
org.apache.commons.net.ftp.FTPConnectionClosedException , you must disconnect the connection with
FTPClient.disconnect disconnect() to properly clean up the
system resources used by FTPClient. Before disconnecting, you may check the
last reply code and text with
org.apache.commons.net.ftp.FTP.getReplyCode getReplyCode ,
org.apache.commons.net.ftp.FTP.getReplyString getReplyString ,
and
org.apache.commons.net.ftp.FTP.getReplyStrings getReplyStrings .
You may avoid server disconnections while the client is idle by
periodicaly sending NOOP commands to the server.
Rather than list it separately for each method, we mention here that
every method communicating with the server and throwing an IOException
can also throw a
org.apache.commons.net.MalformedServerReplyException , which is a subclass
of IOException. A MalformedServerReplyException will be thrown when
the reply received from the server deviates enough from the protocol
specification that it cannot be interpreted in a useful manner despite
attempts to be as lenient as possible.
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.
}
For examples of using FTPClient on servers whose directory listings
- use languages other than English
- use date formats other than the American English "standard"
MM d yyyy
- are in different timezones and you need accurate timestamps for dependency checking
as in Ant
see
FTPClientConfig FTPClientConfig .
NOTE: If you experience problems with unwanted firing of setSoTimeout()
during periods of client inactivity, this can be alleviated by calling setReaderThread(false) .
For more details, see this thread.
author: Daniel F. Savarese See Also: FTP See Also: FTPConnectionClosedException See Also: FTPFileEntryParser See Also: FTPFileEntryParserFactory See Also: DefaultFTPFileEntryParserFactory See Also: FTPClientConfig See Also: org.apache.commons.net.MalformedServerReplyException |
Field Summary | |
final public 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. | final public 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. | final public 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. | final public 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. |
Constructor Summary | |
public | FTPClient() Default FTPClient constructor. |
Method Summary | |
protected void | _connectAction_() | protected Socket | _openDataConnection_(int command, String arg) Establishes a data connection with the FTP server, returning
a Socket for the connection if successful. | public boolean | abort() Abort a transfer in progress.
True if successfully completed, false if not. exception: FTPConnectionClosedException - If the FTP server prematurely closes the connection as a resultof the client being idle or some other reason causing the serverto send FTP reply code 421. | public boolean | allocate(int bytes) Reserve a number of bytes on the server for the next file transfer.
Parameters: bytes - The number of bytes which the server should allocate. | public boolean | allocate(int bytes, int recordSize) Reserve space on the server for the next file transfer.
Parameters: bytes - The number of bytes which the server should allocate. Parameters: recordSize - The size of a file record. | public boolean | appendFile(String remote, InputStream local) Appends to a file on the server with the given name, taking input
from the given InputStream. | public 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. | public boolean | changeToParentDirectory() Change to the parent directory of the current working directory.
True if successfully completed, false if not. exception: FTPConnectionClosedException - If the FTP server prematurely closes the connection as a resultof the client being idle or some other reason causing the serverto send FTP reply code 421. | public boolean | changeWorkingDirectory(String pathname) Change the current working directory of the FTP session.
Parameters: pathname - The new current working directory. | public boolean | completePendingCommand() There are a few FTPClient methods that do not complete the
entire sequence of FTP commands to complete a transaction. | public void | configure(FTPClientConfig config) Implementation of the
Configurable Configurable interface. | public FTPFileList | createFileList(FTPFileEntryParser parser) Using a programmer specified FTPFileEntryParser ,
initialize an object containing a raw file information for the
current working directory. | public FTPFileList | 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. | public boolean | deleteFile(String pathname) Deletes a file on the FTP server.
Parameters: pathname - The pathname of the file to be deleted. | public void | disconnect() Closes the connection to the FTP server and restores
connection parameters to the default values. | public void | enterLocalActiveMode() Set the current data connection mode to
ACTIVE_LOCAL_DATA_CONNECTION_MODE . | public void | enterLocalPassiveMode() Set the current data connection mode to
PASSIVE_LOCAL_DATA_CONNECTION_MODE . | public boolean | enterRemoteActiveMode(InetAddress host, int port) Set the current data connection mode to
ACTIVE_REMOTE_DATA_CONNECTION . | public boolean | enterRemotePassiveMode() Set the current data connection mode to
PASSIVE_REMOTE_DATA_CONNECTION_MODE . | public int | getBufferSize() Retrieve the current internal buffer size. | public int | getDataConnectionMode() Returns the current data connection mode (one of the
_DATA_CONNECTION_MODE constants. | public String | getPassiveHost() Returns the hostname or IP address (in the form of a string) returned
by the server when entering passive mode. | public int | getPassivePort() If in passive mode, returns the data port of the passive host.
This method only returns a valid value AFTER a
data connection has been opened after a call to
FTPClient.enterLocalPassiveMode enterLocalPassiveMode() .
This is because FTPClient sends a PASV command to the server only
just before opening a data connection, and not when you call
FTPClient.enterLocalPassiveMode enterLocalPassiveMode() .
The data port of the passive server. | public long | getRestartOffset() Fetches the restart offset. | public String | getStatus() Issue the FTP STAT command to the server.
The status information returned by the server. exception: FTPConnectionClosedException - If the FTP server prematurely closes the connection as a resultof the client being idle or some other reason causing the serverto send FTP reply code 421. | public String | getStatus(String pathname) Issue the FTP STAT command to the server for a given pathname. | public String | getSystemName() Fetches the system type name from the server and returns the string.
This value is cached for the duration of the connection after the
first call to this method. | public FTPListParseEngine | initiateListParsing() 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. | public FTPListParseEngine | initiateListParsing(String pathname) Using the default autodetect mechanism, initialize an FTPListParseEngine
object containing a raw file information for the supplied directory.
This information is obtained through the LIST command. | public FTPListParseEngine | initiateListParsing(String parserKey, String pathname) Using the supplied parser key, initialize an FTPListParseEngine
object containing a raw file information for the supplied directory.
This information is obtained through the LIST command. | public boolean | isRemoteVerificationEnabled() Return whether or not verification of the remote host participating
in data connections is enabled. | public 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.
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. | public 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.
This information is obtained through the LIST command. | public FTPFile[] | listFiles() Using the default system autodetect mechanism, obtain a
list of file information for the current working directory.
This information is obtained through the LIST command. | public 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. | public FTPFile[] | listFiles(FTPFileListParser parser) Using a programmer specified 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.
Parameters: parser - The FTPFileListParser that should beused to parse the server file listing. | public String | listHelp() Fetches the system help information from the server and returns the
full string.
The system help string obtained from the server. | public String | listHelp(String command) Fetches the help information for a given command from the server and
returns the full string.
Parameters: command - The command on which to ask for help. | public 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). | public String[] | listNames() Obtain a list of filenames in the current working directory
This information is obtained through the NLST command. | public boolean | login(String username, String password) Login to the FTP server using the provided username and password.
Parameters: username - The username to login under. Parameters: password - The password to use. | public boolean | login(String username, String password, String account) Login to the FTP server using the provided username, password,
and account. | public boolean | logout() Logout of the FTP server by sending the QUIT command.
True if successfully completed, false if not. exception: FTPConnectionClosedException - If the FTP server prematurely closes the connection as a resultof the client being idle or some other reason causing the serverto send FTP reply code 421. | public 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).
Parameters: pathname - The pathname of the directory to create. | public String | printWorkingDirectory() Returns the pathname of the current working directory.
The pathname of the current working directory. | boolean | reinitialize() Reinitialize the FTP session. | public boolean | remoteAppend(String filename) Initiate a server to server file transfer. | public boolean | remoteRetrieve(String filename) Initiate a server to server file transfer. | public boolean | remoteStore(String filename) Initiate a server to server file transfer. | public boolean | remoteStoreUnique(String filename) Initiate a server to server file transfer. | public boolean | remoteStoreUnique() Initiate a server to server file transfer. | public boolean | removeDirectory(String pathname) Removes a directory on the FTP server (if empty).
Parameters: pathname - The pathname of the directory to remove. | public boolean | rename(String from, String to) Renames a remote file.
Parameters: from - The name of the remote file to rename. Parameters: to - The new name of the remote file. | public boolean | retrieveFile(String remote, OutputStream local) Retrieves a named file from the server and writes it to the given
OutputStream. | public InputStream | retrieveFileStream(String remote) Returns an InputStream from which a named file from the server
can be read. | public boolean | sendNoOp() Sends a NOOP command to the FTP server. | public boolean | sendSiteCommand(String arguments) Send a site specific command.
Parameters: arguments - The site specific command and arguments. | public void | setBufferSize(int bufSize) Set the internal buffer size. | public void | setDataTimeout(int timeout) Sets the timeout in milliseconds to use when reading from the
data connection. | public boolean | setFileStructure(int structure) Sets the file structure. | public boolean | setFileTransferMode(int mode) Sets the transfer mode. | public boolean | setFileType(int fileType) Sets the file type to be transferred. | public boolean | setFileType(int fileType, int formatOrByteSize) Sets the file type to be transferred and the format. | public void | setParserFactory(FTPFileEntryParserFactory parserFactory) set the factory used for parser creation to the supplied factory object. | public 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. | public void | setRestartOffset(long offset) Sets the restart offset. | public boolean | storeFile(String remote, InputStream local) Stores a file on the server using the given name and taking input
from the given InputStream. | public OutputStream | storeFileStream(String remote) Returns an OutputStream through which data can be written to store
a file on the server using the given name. | public 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. | public 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. | public 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.
If the current file type
is ASCII, the returned OutputStream will convert line separators in
the file to the NETASCII format (i.e., you should not attempt to
create a special OutputStream to do this). | public OutputStream | storeUniqueFileStream() Returns an OutputStream through which data can be written to store
a file on the server using a unique name assigned by the server.
If the current file type
is ASCII, the returned OutputStream will convert line separators in
the file to the NETASCII format (i.e., you should not attempt to
create a special OutputStream to do this). | public boolean | structureMount(String pathname) Issue the FTP SMNT command.
Parameters: pathname - The pathname to mount. |
ACTIVE_LOCAL_DATA_CONNECTION_MODE | final public static int ACTIVE_LOCAL_DATA_CONNECTION_MODE(Code) | | 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.
This is the default data connection mode when and FTPClient instance
is created.
|
ACTIVE_REMOTE_DATA_CONNECTION_MODE | final public static int ACTIVE_REMOTE_DATA_CONNECTION_MODE(Code) | | 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.
|
PASSIVE_LOCAL_DATA_CONNECTION_MODE | final public static int PASSIVE_LOCAL_DATA_CONNECTION_MODE(Code) | | 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.
|
PASSIVE_REMOTE_DATA_CONNECTION_MODE | final public static int PASSIVE_REMOTE_DATA_CONNECTION_MODE(Code) | | 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.
|
FTPClient | public FTPClient()(Code) | | Default FTPClient constructor. Creates a new FTPClient instance
with the data connection mode set to
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 .
|
_openDataConnection_ | protected Socket _openDataConnection_(int command, String arg) throws IOException(Code) | | Establishes a data connection with the FTP server, returning
a Socket for the connection if successful. If a restart
offset has been set with
FTPClient.setRestartOffset(long) ,
a REST command is issued to the server with the offset as
an argument before establishing the data connection. Active
mode connections also cause a local PORT command to be issued.
Parameters: command - The text representation of the FTP command to send. Parameters: arg - The arguments to the FTP command. If this parameter isset to null, then the command is sent with no argument. A Socket corresponding to the established data connection.Null is returned if an FTP protocol error is reported atany point during the establishment and initialization ofthe connection. exception: IOException - If an I/O error occurs while either sending acommand to the server or receiving a reply from the server. |
abort | public boolean abort() throws IOException(Code) | | Abort a transfer in progress.
True if successfully completed, false if not. exception: FTPConnectionClosedException - If the FTP server prematurely closes the connection as a resultof the client being idle or some other reason causing the serverto send FTP reply code 421. This exception may be caught eitheras an IOException or independently as itself. exception: IOException - If an I/O error occurs while either sending acommand to the server or receiving a reply from the server. |
allocate | public boolean allocate(int bytes) throws IOException(Code) | | Reserve a number of bytes on the server for the next file transfer.
Parameters: bytes - The number of bytes which the server should allocate. True if successfully completed, false if not. exception: FTPConnectionClosedException - If the FTP server prematurely closes the connection as a resultof the client being idle or some other reason causing the serverto send FTP reply code 421. This exception may be caught eitheras an IOException or independently as itself. exception: IOException - If an I/O error occurs while either sending acommand to the server or receiving a reply from the server. |
allocate | public boolean allocate(int bytes, int recordSize) throws IOException(Code) | | Reserve space on the server for the next file transfer.
Parameters: bytes - The number of bytes which the server should allocate. Parameters: recordSize - The size of a file record. True if successfully completed, false if not. exception: FTPConnectionClosedException - If the FTP server prematurely closes the connection as a resultof the client being idle or some other reason causing the serverto send FTP reply code 421. This exception may be caught eitheras an IOException or independently as itself. exception: IOException - If an I/O error occurs while either sending acommand to the server or receiving a reply from the server. |
appendFile | public boolean appendFile(String remote, InputStream local) throws IOException(Code) | | Appends to a file on the server with the given name, taking input
from the given InputStream. This method does NOT close the given
InputStream. If the current file type is ASCII, line separators in
the file are transparently converted to the NETASCII format (i.e.,
you should not attempt to create a special InputStream to do this).
Parameters: remote - The name of the remote file. Parameters: local - The local InputStream from which to read the data tobe appended to the remote file. True if successfully completed, false if not. exception: FTPConnectionClosedException - If the FTP server prematurely closes the connection as a resultof the client being idle or some other reason causing the serverto send FTP reply code 421. This exception may be caught eitheras an IOException or independently as itself. exception: CopyStreamException - If an I/O error occurs while actuallytransferring the file. The CopyStreamException allows you todetermine the number of bytes transferred and the IOExceptioncausing the error. This exception may be caught eitheras an IOException or independently as itself. exception: IOException - If an I/O error occurs while either sending acommand to the server or receiving a reply from the server. |
appendFileStream | public OutputStream appendFileStream(String remote) throws IOException(Code) | | Returns an OutputStream through which data can be written to append
to a file on the server with the given name. If the current file type
is ASCII, the returned OutputStream will convert line separators in
the file to the NETASCII format (i.e., you should not attempt to
create a special OutputStream to do this). You must close the
OutputStream when you finish writing to it. The OutputStream itself
will take care of closing the parent data connection socket upon being
closed. To finalize the file transfer you must call
FTPClient.completePendingCommand completePendingCommand and
check its return value to verify success.
Parameters: remote - The name of the remote file. An OutputStream through which the remote file can be appended.If the data connection cannot be opened (e.g., the file does notexist), null is returned (in which case you may check the replycode to determine the exact reason for failure). exception: FTPConnectionClosedException - If the FTP server prematurely closes the connection as a resultof the client being idle or some other reason causing the serverto send FTP reply code 421. This exception may be caught eitheras an IOException or independently as itself. exception: IOException - If an I/O error occurs while either sending acommand to the server or receiving a reply from the server. |
changeToParentDirectory | public boolean changeToParentDirectory() throws IOException(Code) | | Change to the parent directory of the current working directory.
True if successfully completed, false if not. exception: FTPConnectionClosedException - If the FTP server prematurely closes the connection as a resultof the client being idle or some other reason causing the serverto send FTP reply code 421. This exception may be caught eitheras an IOException or independently as itself. exception: IOException - If an I/O error occurs while either sending acommand to the server or receiving a reply from the server. |
changeWorkingDirectory | public boolean changeWorkingDirectory(String pathname) throws IOException(Code) | | Change the current working directory of the FTP session.
Parameters: pathname - The new current working directory. True if successfully completed, false if not. exception: FTPConnectionClosedException - If the FTP server prematurely closes the connection as a resultof the client being idle or some other reason causing the serverto send FTP reply code 421. This exception may be caught eitheras an IOException or independently as itself. exception: IOException - If an I/O error occurs while either sending acommand to the server or receiving a reply from the server. |
completePendingCommand | public boolean completePendingCommand() throws IOException(Code) | | There are a few FTPClient methods that do not complete the
entire sequence of FTP commands to complete a transaction. These
commands require some action by the programmer after the reception
of a positive intermediate command. After the programmer's code
completes its actions, it must call this method to receive
the completion reply from the server and verify the success of the
entire transaction.
For example,
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);
}
True if successfully completed, false if not. exception: FTPConnectionClosedException - If the FTP server prematurely closes the connection as a resultof the client being idle or some other reason causing the serverto send FTP reply code 421. This exception may be caught eitheras an IOException or independently as itself. exception: IOException - If an I/O error occurs while either sending acommand to the server or receiving a reply from the server. |
configure | public void configure(FTPClientConfig config)(Code) | | Implementation of the
Configurable Configurable interface.
In the case of this class, configuring merely makes the config object available for the
factory methods that construct parsers.
Parameters: config - FTPClientConfig FTPClientConfig object used to provide non-standard configurations to the parser. since: 1.4 |
createFileList | public FTPFileList createFileList(FTPFileEntryParser parser) throws IOException(Code) | | Using a programmer specified 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.
Parameters: parser - The FTPFileEntryParser that should beused to parse each server file listing. An iteratable object that holds the raw information and iscapable of providing parsed FTPFile objects, one for each file containinginformation contained in the given path in the format determined by the parser parameter. Null will be returned if adata connection cannot be opened. If the current working directorycontains no files, an empty array will be the return. FTPClient f=FTPClient();f.connect(server);f.login(username, password);FTPFileList list = f.createFileList(directory, parser);FTPFileIterator iter = list.iterator();while (iter.hasNext()) {FTPFile[] files = iter.getNext(25); // "page size" you want//do whatever you want with these files, display them, etc.//expensive FTPFile objects not created until needed.} exception: FTPConnectionClosedException - If the FTP server prematurely closes the connection as a resultof the client being idle or some other reason causing the serverto send FTP reply code 421. This exception may be caught eitheras an IOException or independently as itself. exception: IOException - If an I/O error occurs while either sending acommand to the server or receiving a reply from the server. See Also: FTPFileList |
createFileList | public FTPFileList createFileList(String pathname, FTPFileEntryParser parser) throws IOException(Code) | | Using a programmer specified 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.
Parameters: parser - The FTPFileEntryParser that should beused to parse each server file listing. Parameters: pathname - The file or directory to list. An iteratable object that holds the raw information and iscapable of providing parsed FTPFile objects, one for each file containinginformation contained in the given path in the format determined by the parser parameter. Null will be returned if adata connection cannot be opened. If the supplied path containsno files, an empty array will be the return. exception: FTPConnectionClosedException - If the FTP server prematurely closes the connection as a resultof the client being idle or some other reason causing the serverto send FTP reply code 421. This exception may be caught eitheras an IOException or independently as itself. exception: IOException - If an I/O error occurs while either sending acommand to the server or receiving a reply from the server. See Also: FTPFileList |
deleteFile | public boolean deleteFile(String pathname) throws IOException(Code) | | Deletes a file on the FTP server.
Parameters: pathname - The pathname of the file to be deleted. True if successfully completed, false if not. exception: FTPConnectionClosedException - If the FTP server prematurely closes the connection as a resultof the client being idle or some other reason causing the serverto send FTP reply code 421. This exception may be caught eitheras an IOException or independently as itself. exception: IOException - If an I/O error occurs while either sending acommand to the server or receiving a reply from the server. |
disconnect | public void disconnect() throws IOException(Code) | | Closes the connection to the FTP server and restores
connection parameters to the default values.
exception: IOException - If an error occurs while disconnecting. |
enterLocalActiveMode | public void enterLocalActiveMode()(Code) | | Set the current data connection mode to
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.
|
enterLocalPassiveMode | public void enterLocalPassiveMode()(Code) | | Set the current data connection mode to
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
FTPClient.enterLocalActiveMode enterLocalActiveMode() |
enterRemoteActiveMode | public boolean enterRemoteActiveMode(InetAddress host, int port) throws IOException(Code) | | Set the current data connection mode to
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
FTPClient.enterLocalActiveMode enterLocalActiveMode() if you
wish to return to the normal data connection mode.
Parameters: host - The passive mode server accepting connections for datatransfers. Parameters: port - The passive mode server's data port. True if successfully completed, false if not. exception: FTPConnectionClosedException - If the FTP server prematurely closes the connection as a resultof the client being idle or some other reason causing the serverto send FTP reply code 421. This exception may be caught eitheras an IOException or independently as itself. exception: IOException - If an I/O error occurs while either sending acommand to the server or receiving a reply from the server. |
enterRemotePassiveMode | public boolean enterRemotePassiveMode() throws IOException(Code) | | Set the current data connection mode to
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
FTPClient.enterLocalActiveMode enterLocalActiveMode() if you
wish to return to the normal data connection mode.
True if successfully completed, false if not. exception: FTPConnectionClosedException - If the FTP server prematurely closes the connection as a resultof the client being idle or some other reason causing the serverto send FTP reply code 421. This exception may be caught eitheras an IOException or independently as itself. exception: IOException - If an I/O error occurs while either sending acommand to the server or receiving a reply from the server. |
getBufferSize | public int getBufferSize()(Code) | | Retrieve the current internal buffer size.
The current buffer size. |
getDataConnectionMode | public int getDataConnectionMode()(Code) | | Returns the current data connection mode (one of the
_DATA_CONNECTION_MODE constants.
The current data connection mode (one of the _DATA_CONNECTION_MODE constants. |
getPassiveHost | public String getPassiveHost()(Code) | | Returns the hostname or IP address (in the form of a string) returned
by the server when entering passive mode. If not in passive mode,
returns null. This method only returns a valid value AFTER a
data connection has been opened after a call to
FTPClient.enterLocalPassiveMode enterLocalPassiveMode() .
This is because FTPClient sends a PASV command to the server only
just before opening a data connection, and not when you call
FTPClient.enterLocalPassiveMode enterLocalPassiveMode() .
The passive host name if in passive mode, otherwise null. |
getPassivePort | public int getPassivePort()(Code) | | If in passive mode, returns the data port of the passive host.
This method only returns a valid value AFTER a
data connection has been opened after a call to
FTPClient.enterLocalPassiveMode enterLocalPassiveMode() .
This is because FTPClient sends a PASV command to the server only
just before opening a data connection, and not when you call
FTPClient.enterLocalPassiveMode enterLocalPassiveMode() .
The data port of the passive server. If not in passivemode, undefined. |
getRestartOffset | public long getRestartOffset()(Code) | | Fetches the restart offset.
offset The offset into the remote file at which to start thenext file transfer. |
getStatus | public String getStatus() throws IOException(Code) | | Issue the FTP STAT command to the server.
The status information returned by the server. exception: FTPConnectionClosedException - If the FTP server prematurely closes the connection as a resultof the client being idle or some other reason causing the serverto send FTP reply code 421. This exception may be caught eitheras an IOException or independently as itself. exception: IOException - If an I/O error occurs while either sending acommand to the server or receiving a reply from the server. |
getStatus | public String getStatus(String pathname) throws IOException(Code) | | Issue the FTP STAT command to the server for a given pathname. This
should produce a listing of the file or directory.
The status information returned by the server. exception: FTPConnectionClosedException - If the FTP server prematurely closes the connection as a resultof the client being idle or some other reason causing the serverto send FTP reply code 421. This exception may be caught eitheras an IOException or independently as itself. exception: IOException - If an I/O error occurs while either sending acommand to the server or receiving a reply from the server. |
getSystemName | public String getSystemName() throws IOException(Code) | | Fetches the system type name from the server and returns the string.
This value is cached for the duration of the connection after the
first call to this method. In other words, only the first time
that you invoke this method will it issue a SYST command to the
FTP server. FTPClient will remember the value and return the
cached value until a call to disconnect.
The system type name obtained from the server. null if theinformation could not be obtained. exception: FTPConnectionClosedException - If the FTP server prematurely closes the connection as a resultof the client being idle or some other reason causing the serverto send FTP reply code 421. This exception may be caught eitheras an IOException or independently as itself. exception: IOException - If an I/O error occurs while either sending acommand to the server or receiving a reply from the server. |
initiateListParsing | public FTPListParseEngine initiateListParsing() throws IOException(Code) | | 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. This object
is then capable of being iterated to return a sequence of FTPFile
objects with information filled in by the
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.
A FTPListParseEngine object that holds the raw information andis capable of providing parsed FTPFile objects, one for each filecontaining information contained in the given path in the formatdetermined by the parser parameter. Null will bereturned if a data connection cannot be opened. If the current workingdirectory contains no files, an empty array will be the return. exception: FTPConnectionClosedException - If the FTP server prematurely closes the connection as a resultof the client being idle or some other reason causing the serverto send FTP reply code 421. This exception may be caught eitheras an IOException or independently as itself. exception: IOException - If an I/O error occurs while either sending acommand to the server or receiving a reply from the server. exception: ParserInitializationException - Thrown if the autodetect mechanism cannotresolve the type of system we are connected with. See Also: FTPListParseEngine |
initiateListParsing | public FTPListParseEngine initiateListParsing(String pathname) throws IOException(Code) | | Using the default autodetect mechanism, initialize an FTPListParseEngine
object containing a raw file information for the supplied 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.
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.
}
A FTPListParseEngine object that holds the raw information andis capable of providing parsed FTPFile objects, one for each filecontaining information contained in the given path in the formatdetermined by the parser parameter. Null will bereturned if a data connection cannot be opened. If the current workingdirectory contains no files, an empty array will be the return. exception: FTPConnectionClosedException - If the FTP server prematurely closes the connection as a resultof the client being idle or some other reason causing the serverto send FTP reply code 421. This exception may be caught eitheras an IOException or independently as itself. exception: IOException - If an I/O error occurs while either sending acommand to the server or receiving a reply from the server. exception: ParserInitializationException - Thrown if the autodetect mechanism cannotresolve the type of system we are connected with. See Also: FTPListParseEngine |
initiateListParsing | public FTPListParseEngine initiateListParsing(String parserKey, String pathname) throws IOException(Code) | | Using the supplied parser key, initialize an FTPListParseEngine
object containing a raw file information for the supplied 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.
Parameters: parserKey - A string representing a designated code or fully-qualifiedclass name of an FTPFileEntryParser that should beused to parse each server file listing. A FTPListParseEngine object that holds the raw information andis capable of providing parsed FTPFile objects, one for each filecontaining information contained in the given path in the formatdetermined by the parser parameter. Null will bereturned if a data connection cannot be opened. If the current workingdirectory contains no files, an empty array will be the return. exception: FTPConnectionClosedException - If the FTP server prematurely closes the connection as a resultof the client being idle or some other reason causing the serverto send FTP reply code 421. This exception may be caught eitheras an IOException or independently as itself. exception: IOException - If an I/O error occurs while either sending acommand to the server or receiving a reply from the server. exception: ParserInitializationException - Thrown if the parserKey parameter cannot beresolved by the selected parser factory.In the DefaultFTPEntryParserFactory, this willhappen when parserKey is neitherthe fully qualified class name of a classimplementing the interfaceorg.apache.commons.net.ftp.FTPFileEntryParsernor a string containing one of the recognized keysmapping to such a parser or if class loadersecurity issues prevent its being loaded. See Also: FTPListParseEngine |
isRemoteVerificationEnabled | public boolean isRemoteVerificationEnabled()(Code) | | Return whether or not verification of the remote host participating
in data connections is enabled. The default behavior is for
verification to be enabled.
True if verification is enabled, false if not. |
listFiles | public FTPFile[] listFiles(String parserKey, String pathname) throws IOException(Code) | | Using the supplied 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.
Parameters: parserKey - This is a "handle" which the parser factory usedmust be able to resolve into a class implementingFTPFileEntryParser. In the DefaultFTPFileEntryParserFactory, thismay either be a specific key identifying a server type,which is used to identify a parser type,or the fully qualified class name of the parser. SeeDefaultFTPFileEntryParserFactory.createFileEntryParserfor full details. If this parameter is null, will attempt to generate a keyby running the SYST command. This should cause no problemwith the functionality implemented in theDefaultFTPFileEntryParserFactory, but may not map so wellto an alternative user-created factory. If that is thecase, calling this routine with a null parameter and acustom parser factory may not be advisable. Parameters: pathname - The file or directory to list. Since the server mayor may not expand glob expressions, using them hereis not recommended and may well cause this method tofail. The list of file information contained in the given path inthe format determined by the parser represented by the parserKey parameter.
NOTE: This array may contain null members if any of the individual file listings failed to parse. The caller should check each entry for null before referencing it. exception: FTPConnectionClosedException - If the FTP server prematurely closes the connectionas a result of the client being idle or some otherreason causing the server to send FTP reply code 421.This exception may be caught either as an IOExceptionor independently as itself. exception: IOException - If an I/O error occurs while either sending acommand to the server or receiving a replyfrom the server. exception: ParserInitializationException - Thrown if the parserKey parameter cannot beresolved by the selected parser factory.In the DefaultFTPEntryParserFactory, this willhappen when parserKey is neitherthe fully qualified class name of a classimplementing the interfaceorg.apache.commons.net.ftp.FTPFileEntryParsernor a string containing one of the recognized keysmapping to such a parser or if class loadersecurity issues prevent its being loaded. See Also: org.apache.commons.net.ftp.parser.DefaultFTPFileEntryParserFactory See Also: org.apache.commons.net.ftp.parser.FTPFileEntryParserFactory See Also: org.apache.commons.net.ftp.FTPFileEntryParserFTPClient.listFiles() listFiles()FTPClient.listFiles(String) listFiles(String)FTPClient.FTPClientConfig FTPClientConfig |
listFiles | public FTPFile[] listFiles(String pathname) throws IOException(Code) | | Using the default system autodetect mechanism, obtain a
list of file information for the current working directory
or for just a single file.
This information is obtained through the LIST command. The contents of
the returned array is determined by the FTPFileEntryParser
used.
Parameters: pathname - The file or directory to list. Since the server mayor may not expand glob expressions, using them hereis not recommended and may well cause this method tofail. The list of file information contained in the given path inthe format determined by the autodetection mechanism exception: FTPConnectionClosedException - If the FTP server prematurely closes the connectionas a result of the client being idle or some otherreason causing the server to send FTP reply code 421.This exception may be caught either as an IOExceptionor independently as itself. exception: IOException - If an I/O error occurs while either sending acommand to the server or receiving a replyfrom the server. exception: ParserInitializationException - Thrown if the parserKey parameter cannot beresolved by the selected parser factory.In the DefaultFTPEntryParserFactory, this willhappen when parserKey is neitherthe fully qualified class name of a classimplementing the interfaceorg.apache.commons.net.ftp.FTPFileEntryParsernor a string containing one of the recognized keysmapping to such a parser or if class loadersecurity issues prevent its being loaded. See Also: org.apache.commons.net.ftp.parser.DefaultFTPFileEntryParserFactory See Also: org.apache.commons.net.ftp.parser.FTPFileEntryParserFactory See Also: org.apache.commons.net.ftp.FTPFileEntryParser |
listFiles | public FTPFile[] listFiles() throws IOException(Code) | | Using the default system autodetect mechanism, obtain a
list of file information for the current working directory.
This information is obtained through the LIST command. The contents of
the returned array is determined by the FTPFileEntryParser
used.
The list of file information contained in the current directoryin the format determined by the autodetection mechanism. NOTE: This array may contain null members if any of the individual file listings failed to parse. The caller should check each entry for null before referencing it. exception: FTPConnectionClosedException - If the FTP server prematurely closes the connectionas a result of the client being idle or some otherreason causing the server to send FTP reply code 421.This exception may be caught either as an IOExceptionor independently as itself. exception: IOException - If an I/O error occurs while either sending acommand to the server or receiving a replyfrom the server. exception: ParserInitializationException - Thrown if the parserKey parameter cannot beresolved by the selected parser factory.In the DefaultFTPEntryParserFactory, this willhappen when parserKey is neitherthe fully qualified class name of a classimplementing the interfaceorg.apache.commons.net.ftp.FTPFileEntryParsernor a string containing one of the recognized keysmapping to such a parser or if class loadersecurity issues prevent its being loaded. See Also: org.apache.commons.net.ftp.parser.DefaultFTPFileEntryParserFactory See Also: org.apache.commons.net.ftp.parser.FTPFileEntryParserFactory See Also: org.apache.commons.net.ftp.FTPFileEntryParser |
listFiles | public FTPFile[] listFiles(FTPFileListParser parser, String pathname) throws IOException(Code) | | Using a programmer specified 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.
Parameters: parser - The FTPFileListParser that should beused to parse the server file listing. Parameters: pathname - The file or directory to list. The list of file information contained in the given path inthe format determined by the parser parameter. NOTE: This array may contain null members if any of the individual file listings failed to parse. The caller should check each entry for null before referencing it. exception: FTPConnectionClosedException - If the FTP server prematurely closes the connection as a resultof the client being idle or some other reason causing the serverto send FTP reply code 421. This exception may be caught eitheras an IOException or independently as itself. exception: IOException - If an I/O error occurs while either sending acommand to the server or receiving a reply from the server. The list of file information contained in the given path inthe format determined by parserKey parameter. NOTE: This array may contain null members if any of the individual file listings failed to parse. The caller should check each entry for null before referencing it. exception: IOException - since: 5 Jan 2004 |
listFiles | public FTPFile[] listFiles(FTPFileListParser parser) throws IOException(Code) | | Using a programmer specified 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.
Parameters: parser - The FTPFileListParser that should beused to parse the server file listing. The list of file information contained in the given path inthe format determined by the parser parameter. NOTE: This array may contain null members if any of the individual file listings failed to parse. The caller should check each entry for null before referencing it. exception: FTPConnectionClosedException - If the FTP server prematurely closes the connection as a resultof the client being idle or some other reason causing the serverto send FTP reply code 421. This exception may be caught eitheras an IOException or independently as itself. exception: IOException - If an I/O error occurs while either sending acommand to the server or receiving a reply from the server. exception: IOException - since: 5 Jan 2004 |
listHelp | public String listHelp() throws IOException(Code) | | Fetches the system help information from the server and returns the
full string.
The system help string obtained from the server. null if theinformation could not be obtained. exception: FTPConnectionClosedException - If the FTP server prematurely closes the connection as a resultof the client being idle or some other reason causing the serverto send FTP reply code 421. This exception may be caught eitheras an IOException or independently as itself. exception: IOException - If an I/O error occurs while either sending acommand to the server or receiving a reply from the server. |
listHelp | public String listHelp(String command) throws IOException(Code) | | Fetches the help information for a given command from the server and
returns the full string.
Parameters: command - The command on which to ask for help. The command help string obtained from the server. null if theinformation could not be obtained. exception: FTPConnectionClosedException - If the FTP server prematurely closes the connection as a resultof the client being idle or some other reason causing the serverto send FTP reply code 421. This exception may be caught eitheras an IOException or independently as itself. exception: IOException - If an I/O error occurs while either sending acommand to the server or receiving a reply from the server. |
listNames | public String[] listNames(String pathname) throws IOException(Code) | | Obtain a list of filenames in a directory (or just the name of a given
file, which is not particularly useful). This information is obtained
through the NLST command. If the given pathname is a directory and
contains no files, a zero length array is returned only
if the FTP server returned a positive completion code, otherwise
null is returned (the FTP server returned a 550 error No files found.).
If the directory is not empty, an array of filenames in the directory is
returned. If the pathname corresponds
to a file, only that file will be listed. The server may or may not
expand glob expressions.
Parameters: pathname - The file or directory to list. The list of filenames contained in the given path. null ifthe list could not be obtained. If there are no filenames inthe directory, a zero-length array is returned. exception: FTPConnectionClosedException - If the FTP server prematurely closes the connection as a resultof the client being idle or some other reason causing the serverto send FTP reply code 421. This exception may be caught eitheras an IOException or independently as itself. exception: IOException - If an I/O error occurs while either sending acommand to the server or receiving a reply from the server. |
listNames | public String[] listNames() throws IOException(Code) | | Obtain a list of filenames in the current working directory
This information is obtained through the NLST command. If the current
directory contains no files, a zero length array is returned only
if the FTP server returned a positive completion code, otherwise,
null is returned (the FTP server returned a 550 error No files found.).
If the directory is not empty, an array of filenames in the directory is
returned.
The list of filenames contained in the current workingdirectory. null if the list could not be obtained.If there are no filenames in the directory, a zero-length arrayis returned. exception: FTPConnectionClosedException - If the FTP server prematurely closes the connection as a resultof the client being idle or some other reason causing the serverto send FTP reply code 421. This exception may be caught eitheras an IOException or independently as itself. exception: IOException - If an I/O error occurs while either sending acommand to the server or receiving a reply from the server. |
login | public boolean login(String username, String password) throws IOException(Code) | | Login to the FTP server using the provided username and password.
Parameters: username - The username to login under. Parameters: password - The password to use. True if successfully completed, false if not. exception: FTPConnectionClosedException - If the FTP server prematurely closes the connection as a resultof the client being idle or some other reason causing the serverto send FTP reply code 421. This exception may be caught eitheras an IOException or independently as itself. exception: IOException - If an I/O error occurs while either sending acommand to the server or receiving a reply from the server. |
login | public boolean login(String username, String password, String account) throws IOException(Code) | | Login to the FTP server using the provided username, password,
and account. If no account is required by the server, only
the username and password, the account information is not used.
Parameters: username - The username to login under. Parameters: password - The password to use. Parameters: account - The account to use. True if successfully completed, false if not. exception: FTPConnectionClosedException - If the FTP server prematurely closes the connection as a resultof the client being idle or some other reason causing the serverto send FTP reply code 421. This exception may be caught eitheras an IOException or independently as itself. exception: IOException - If an I/O error occurs while either sending acommand to the server or receiving a reply from the server. |
logout | public boolean logout() throws IOException(Code) | | Logout of the FTP server by sending the QUIT command.
True if successfully completed, false if not. exception: FTPConnectionClosedException - If the FTP server prematurely closes the connection as a resultof the client being idle or some other reason causing the serverto send FTP reply code 421. This exception may be caught eitheras an IOException or independently as itself. exception: IOException - If an I/O error occurs while either sending acommand to the server or receiving a reply from the server. |
makeDirectory | public boolean makeDirectory(String pathname) throws IOException(Code) | | 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).
Parameters: pathname - The pathname of the directory to create. True if successfully completed, false if not. exception: FTPConnectionClosedException - If the FTP server prematurely closes the connection as a resultof the client being idle or some other reason causing the serverto send FTP reply code 421. This exception may be caught eitheras an IOException or independently as itself. exception: IOException - If an I/O error occurs while either sending acommand to the server or receiving a reply from the server. |
printWorkingDirectory | public String printWorkingDirectory() throws IOException(Code) | | Returns the pathname of the current working directory.
The pathname of the current working directory. If it cannotbe obtained, returns null. exception: FTPConnectionClosedException - If the FTP server prematurely closes the connection as a resultof the client being idle or some other reason causing the serverto send FTP reply code 421. This exception may be caught eitheras an IOException or independently as itself. exception: IOException - If an I/O error occurs while either sending acommand to the server or receiving a reply from the server. |
reinitialize | boolean reinitialize() throws IOException(Code) | | Reinitialize the FTP session. Not all FTP servers support this
command, which issues the FTP REIN command.
True if successfully completed, false if not. exception: FTPConnectionClosedException - If the FTP server prematurely closes the connection as a resultof the client being idle or some other reason causing the serverto send FTP reply code 421. This exception may be caught eitheras an IOException or independently as itself. exception: IOException - If an I/O error occurs while either sending acommand to the server or receiving a reply from the server. |
remoteAppend | public boolean remoteAppend(String filename) throws IOException(Code) | | Initiate a server to server file transfer. This method tells the
server to which the client is connected to append to a given file on
the other server. The other server must have had a
remoteRetrieve issued to it by another FTPClient.
Parameters: filename - The name of the file to be appended to, or if thefile does not exist, the name to call the file being stored. True if successfully completed, false if not. exception: FTPConnectionClosedException - If the FTP server prematurely closes the connection as a resultof the client being idle or some other reason causing the serverto send FTP reply code 421. This exception may be caught eitheras an IOException or independently as itself. exception: IOException - If an I/O error occurs while either sending acommand to the server or receiving a reply from the server. |
remoteRetrieve | public boolean remoteRetrieve(String filename) throws IOException(Code) | | Initiate a server to server file transfer. This method tells the
server to which the client is connected to retrieve a given file from
the other server.
Parameters: filename - The name of the file to retrieve. True if successfully completed, false if not. exception: FTPConnectionClosedException - If the FTP server prematurely closes the connection as a resultof the client being idle or some other reason causing the serverto send FTP reply code 421. This exception may be caught eitheras an IOException or independently as itself. exception: IOException - If an I/O error occurs while either sending acommand to the server or receiving a reply from the server. |
remoteStore | public boolean remoteStore(String filename) throws IOException(Code) | | Initiate a server to server file transfer. This method tells the
server to which the client is connected to store a file on
the other server using the given filename. The other server must
have had a remoteRetrieve issued to it by another
FTPClient.
Parameters: filename - The name to call the file that is to be stored. True if successfully completed, false if not. exception: FTPConnectionClosedException - If the FTP server prematurely closes the connection as a resultof the client being idle or some other reason causing the serverto send FTP reply code 421. This exception may be caught eitheras an IOException or independently as itself. exception: IOException - If an I/O error occurs while either sending acommand to the server or receiving a reply from the server. |
remoteStoreUnique | public boolean remoteStoreUnique(String filename) throws IOException(Code) | | Initiate a server to server file transfer. This method tells the
server to which the client is connected to store a file on
the other server using a unique filename based on the given filename.
The other server must have had a remoteRetrieve issued
to it by another FTPClient.
Parameters: filename - The name on which to base the filename of the filethat is to be stored. True if successfully completed, false if not. exception: FTPConnectionClosedException - If the FTP server prematurely closes the connection as a resultof the client being idle or some other reason causing the serverto send FTP reply code 421. This exception may be caught eitheras an IOException or independently as itself. exception: IOException - If an I/O error occurs while either sending acommand to the server or receiving a reply from the server. |
remoteStoreUnique | public boolean remoteStoreUnique() throws IOException(Code) | | Initiate a server to server file transfer. This method tells the
server to which the client is connected to store a file on
the other server using a unique filename.
The other server must have had a 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
True if successfully completed, false if not. exception: FTPConnectionClosedException - If the FTP server prematurely closes the connection as a resultof the client being idle or some other reason causing the serverto send FTP reply code 421. This exception may be caught eitheras an IOException or independently as itself. exception: IOException - If an I/O error occurs while either sending acommand to the server or receiving a reply from the server. |
removeDirectory | public boolean removeDirectory(String pathname) throws IOException(Code) | | Removes a directory on the FTP server (if empty).
Parameters: pathname - The pathname of the directory to remove. True if successfully completed, false if not. exception: FTPConnectionClosedException - If the FTP server prematurely closes the connection as a resultof the client being idle or some other reason causing the serverto send FTP reply code 421. This exception may be caught eitheras an IOException or independently as itself. exception: IOException - If an I/O error occurs while either sending acommand to the server or receiving a reply from the server. |
rename | public boolean rename(String from, String to) throws IOException(Code) | | Renames a remote file.
Parameters: from - The name of the remote file to rename. Parameters: to - The new name of the remote file. True if successfully completed, false if not. exception: FTPConnectionClosedException - If the FTP server prematurely closes the connection as a resultof the client being idle or some other reason causing the serverto send FTP reply code 421. This exception may be caught eitheras an IOException or independently as itself. exception: IOException - If an I/O error occurs while either sending acommand to the server or receiving a reply from the server. |
retrieveFile | public boolean retrieveFile(String remote, OutputStream local) throws IOException(Code) | | Retrieves a named file from the server and writes it to the given
OutputStream. This method does NOT close the given OutputStream.
If the current file type is ASCII, line separators in the file are
converted to the local representation.
Parameters: remote - The name of the remote file. Parameters: local - The local OutputStream to which to write the file. True if successfully completed, false if not. exception: FTPConnectionClosedException - If the FTP server prematurely closes the connection as a resultof the client being idle or some other reason causing the serverto send FTP reply code 421. This exception may be caught eitheras an IOException or independently as itself. exception: CopyStreamException - If an I/O error occurs while actuallytransferring the file. The CopyStreamException allows you todetermine the number of bytes transferred and the IOExceptioncausing the error. This exception may be caught eitheras an IOException or independently as itself. exception: IOException - If an I/O error occurs while either sending acommand to the server or receiving a reply from the server. |
retrieveFileStream | public InputStream retrieveFileStream(String remote) throws IOException(Code) | | Returns an InputStream from which a named file from the server
can be read. If the current file type is ASCII, the returned
InputStream will convert line separators in the file to
the local representation. You must close the InputStream when you
finish reading from it. The InputStream itself will take care of
closing the parent data connection socket upon being closed. To
finalize the file transfer you must call
FTPClient.completePendingCommand completePendingCommand and
check its return value to verify success.
Parameters: remote - The name of the remote file. An InputStream from which the remote file can be read. Ifthe data connection cannot be opened (e.g., the file does notexist), null is returned (in which case you may check the replycode to determine the exact reason for failure). exception: FTPConnectionClosedException - If the FTP server prematurely closes the connection as a resultof the client being idle or some other reason causing the serverto send FTP reply code 421. This exception may be caught eitheras an IOException or independently as itself. exception: IOException - If an I/O error occurs while either sending acommand to the server or receiving a reply from the server. |
sendNoOp | public boolean sendNoOp() throws IOException(Code) | | Sends a NOOP command to the FTP server. This is useful for preventing
server timeouts.
True if successfully completed, false if not. exception: FTPConnectionClosedException - If the FTP server prematurely closes the connection as a resultof the client being idle or some other reason causing the serverto send FTP reply code 421. This exception may be caught eitheras an IOException or independently as itself. exception: IOException - If an I/O error occurs while either sending acommand to the server or receiving a reply from the server. |
sendSiteCommand | public boolean sendSiteCommand(String arguments) throws IOException(Code) | | Send a site specific command.
Parameters: arguments - The site specific command and arguments. True if successfully completed, false if not. exception: FTPConnectionClosedException - If the FTP server prematurely closes the connection as a resultof the client being idle or some other reason causing the serverto send FTP reply code 421. This exception may be caught eitheras an IOException or independently as itself. exception: IOException - If an I/O error occurs while either sending acommand to the server or receiving a reply from the server. |
setBufferSize | public void setBufferSize(int bufSize)(Code) | | Set the internal buffer size.
Parameters: bufSize - The size of the buffer |
setDataTimeout | public void setDataTimeout(int timeout)(Code) | | Sets the timeout in milliseconds to use when reading from the
data connection. This timeout will be set immediately after
opening the data connection.
Parameters: timeout - The default timeout in milliseconds that is used whenopening a data connection socket. |
setFileStructure | public boolean setFileStructure(int structure) throws IOException(Code) | | Sets the file structure. The default structure is
FTP.FILE_STRUCTURE if this method is never called.
Parameters: structure - The structure of the file (one of the FTP class_STRUCTURE constants). True if successfully completed, false if not. exception: FTPConnectionClosedException - If the FTP server prematurely closes the connection as a resultof the client being idle or some other reason causing the serverto send FTP reply code 421. This exception may be caught eitheras an IOException or independently as itself. exception: IOException - If an I/O error occurs while either sending acommand to the server or receiving a reply from the server. |
setFileTransferMode | public boolean setFileTransferMode(int mode) throws IOException(Code) | | Sets the transfer mode. The default transfer mode
FTP.STREAM_TRANSFER_MODE if this method is never called.
Parameters: mode - The new transfer mode to use (one of the FTP class_TRANSFER_MODE constants). True if successfully completed, false if not. exception: FTPConnectionClosedException - If the FTP server prematurely closes the connection as a resultof the client being idle or some other reason causing the serverto send FTP reply code 421. This exception may be caught eitheras an IOException or independently as itself. exception: IOException - If an I/O error occurs while either sending acommand to the server or receiving a reply from the server. |
setFileType | public boolean setFileType(int fileType) throws IOException(Code) | | Sets the file type to be transferred. This should be one of
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.
Parameters: fileType - The _FILE_TYPE constant indcating thetype of file. True if successfully completed, false if not. exception: FTPConnectionClosedException - If the FTP server prematurely closes the connection as a resultof the client being idle or some other reason causing the serverto send FTP reply code 421. This exception may be caught eitheras an IOException or independently as itself. exception: IOException - If an I/O error occurs while either sending acommand to the server or receiving a reply from the server. |
setFileType | public boolean setFileType(int fileType, int formatOrByteSize) throws IOException(Code) | | Sets the file type to be transferred and the format. The type should be
one of 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.
Parameters: fileType - The _FILE_TYPE constant indcating thetype of file. Parameters: formatOrByteSize - The format of the file (one of the_FORMAT constants. In the case ofLOCAL_FILE_TYPE , the byte size. True if successfully completed, false if not. exception: FTPConnectionClosedException - If the FTP server prematurely closes the connection as a resultof the client being idle or some other reason causing the serverto send FTP reply code 421. This exception may be caught eitheras an IOException or independently as itself. exception: IOException - If an I/O error occurs while either sending acommand to the server or receiving a reply from the server. |
setRemoteVerificationEnabled | public void setRemoteVerificationEnabled(boolean enable)(Code) | | 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. The default is for verification to be
enabled. You may set this value at any time, whether the
FTPClient is currently connected or not.
Parameters: enable - True to enable verification, false to disable verification. |
setRestartOffset | public void setRestartOffset(long offset)(Code) | | Sets the restart offset. The restart command is sent to the server
only before sending the file transfer command. When this is done,
the restart marker is reset to zero.
Parameters: offset - The offset into the remote file at which to start thenext file transfer. This must be a value greater than orequal to zero. |
storeFile | public boolean storeFile(String remote, InputStream local) throws IOException(Code) | | Stores a file on the server using the given name and taking input
from the given InputStream. This method does NOT close the given
InputStream. If the current file type is ASCII, line separators in
the file are transparently converted to the NETASCII format (i.e.,
you should not attempt to create a special InputStream to do this).
Parameters: remote - The name to give the remote file. Parameters: local - The local InputStream from which to read the file. True if successfully completed, false if not. exception: FTPConnectionClosedException - If the FTP server prematurely closes the connection as a resultof the client being idle or some other reason causing the serverto send FTP reply code 421. This exception may be caught eitheras an IOException or independently as itself. exception: CopyStreamException - If an I/O error occurs while actuallytransferring the file. The CopyStreamException allows you todetermine the number of bytes transferred and the IOExceptioncausing the error. This exception may be caught eitheras an IOException or independently as itself. exception: IOException - If an I/O error occurs while either sending acommand to the server or receiving a reply from the server. |
storeFileStream | public OutputStream storeFileStream(String remote) throws IOException(Code) | | Returns an OutputStream through which data can be written to store
a file on the server using the given name. If the current file type
is ASCII, the returned OutputStream will convert line separators in
the file to the NETASCII format (i.e., you should not attempt to
create a special OutputStream to do this). You must close the
OutputStream when you finish writing to it. The OutputStream itself
will take care of closing the parent data connection socket upon being
closed. To finalize the file transfer you must call
FTPClient.completePendingCommand completePendingCommand and
check its return value to verify success.
Parameters: remote - The name to give the remote file. An OutputStream through which the remote file can be written. Ifthe data connection cannot be opened (e.g., the file does notexist), null is returned (in which case you may check the replycode to determine the exact reason for failure). exception: FTPConnectionClosedException - If the FTP server prematurely closes the connection as a resultof the client being idle or some other reason causing the serverto send FTP reply code 421. This exception may be caught eitheras an IOException or independently as itself. exception: IOException - If an I/O error occurs while either sending acommand to the server or receiving a reply from the server. |
storeUniqueFile | public boolean storeUniqueFile(String remote, InputStream local) throws IOException(Code) | | Stores a file on the server using a unique name derived from the
given name and taking input
from the given InputStream. This method does NOT close the given
InputStream. If the current file type is ASCII, line separators in
the file are transparently converted to the NETASCII format (i.e.,
you should not attempt to create a special InputStream to do this).
Parameters: remote - The name on which to base the unique name given tothe remote file. Parameters: local - The local InputStream from which to read the file. True if successfully completed, false if not. exception: FTPConnectionClosedException - If the FTP server prematurely closes the connection as a resultof the client being idle or some other reason causing the serverto send FTP reply code 421. This exception may be caught eitheras an IOException or independently as itself. exception: CopyStreamException - If an I/O error occurs while actuallytransferring the file. The CopyStreamException allows you todetermine the number of bytes transferred and the IOExceptioncausing the error. This exception may be caught eitheras an IOException or independently as itself. exception: IOException - If an I/O error occurs while either sending acommand to the server or receiving a reply from the server. |
storeUniqueFile | public boolean storeUniqueFile(InputStream local) throws IOException(Code) | | Stores a file on the server using a unique name assigned by the
server and taking input from the given InputStream. This method does
NOT close the given
InputStream. If the current file type is ASCII, line separators in
the file are transparently converted to the NETASCII format (i.e.,
you should not attempt to create a special InputStream to do this).
Parameters: local - The local InputStream from which to read the file. True if successfully completed, false if not. exception: FTPConnectionClosedException - If the FTP server prematurely closes the connection as a resultof the client being idle or some other reason causing the serverto send FTP reply code 421. This exception may be caught eitheras an IOException or independently as itself. exception: CopyStreamException - If an I/O error occurs while actuallytransferring the file. The CopyStreamException allows you todetermine the number of bytes transferred and the IOExceptioncausing the error. This exception may be caught eitheras an IOException or independently as itself. exception: IOException - If an I/O error occurs while either sending acommand to the server or receiving a reply from the server. |
storeUniqueFileStream | public OutputStream storeUniqueFileStream(String remote) throws IOException(Code) | | 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.
If the current file type
is ASCII, the returned OutputStream will convert line separators in
the file to the NETASCII format (i.e., you should not attempt to
create a special OutputStream to do this). You must close the
OutputStream when you finish writing to it. The OutputStream itself
will take care of closing the parent data connection socket upon being
closed. To finalize the file transfer you must call
FTPClient.completePendingCommand completePendingCommand and
check its return value to verify success.
Parameters: remote - The name on which to base the unique name given tothe remote file. An OutputStream through which the remote file can be written. Ifthe data connection cannot be opened (e.g., the file does notexist), null is returned (in which case you may check the replycode to determine the exact reason for failure). exception: FTPConnectionClosedException - If the FTP server prematurely closes the connection as a resultof the client being idle or some other reason causing the serverto send FTP reply code 421. This exception may be caught eitheras an IOException or independently as itself. exception: IOException - If an I/O error occurs while either sending acommand to the server or receiving a reply from the server. |
storeUniqueFileStream | public OutputStream storeUniqueFileStream() throws IOException(Code) | | Returns an OutputStream through which data can be written to store
a file on the server using a unique name assigned by the server.
If the current file type
is ASCII, the returned OutputStream will convert line separators in
the file to the NETASCII format (i.e., you should not attempt to
create a special OutputStream to do this). You must close the
OutputStream when you finish writing to it. The OutputStream itself
will take care of closing the parent data connection socket upon being
closed. To finalize the file transfer you must call
FTPClient.completePendingCommand completePendingCommand and
check its return value to verify success.
An OutputStream through which the remote file can be written. Ifthe data connection cannot be opened (e.g., the file does notexist), null is returned (in which case you may check the replycode to determine the exact reason for failure). exception: FTPConnectionClosedException - If the FTP server prematurely closes the connection as a resultof the client being idle or some other reason causing the serverto send FTP reply code 421. This exception may be caught eitheras an IOException or independently as itself. exception: IOException - If an I/O error occurs while either sending acommand to the server or receiving a reply from the server. |
structureMount | public boolean structureMount(String pathname) throws IOException(Code) | | Issue the FTP SMNT command.
Parameters: pathname - The pathname to mount. True if successfully completed, false if not. exception: FTPConnectionClosedException - If the FTP server prematurely closes the connection as a resultof the client being idle or some other reason causing the serverto send FTP reply code 421. This exception may be caught eitheras an IOException or independently as itself. exception: IOException - If an I/O error occurs while either sending acommand to the server or receiving a reply from the server. |
|
|