|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--com.oroinc.net.SocketClient | +--com.oroinc.net.telnet.Telnet | +--com.oroinc.net.telnet.TelnetClient | +--com.oroinc.net.ftp.FTP | +--com.oroinc.net.ftp.FTPClient
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 SocketClient , you must first connect to the server with connect before doing anything, and finally 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:
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 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 NetASCII filter streams in
com.oroinc.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
, 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 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 .
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
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.
FTP
,
FTPConnectionClosedException
,
DefaultFTPFileListParser
,
MalformedServerReplyException
Field Summary | |
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. |
Fields inherited from class com.oroinc.net.ftp.FTP |
_commandSupport_, ASCII_FILE_TYPE, BINARY_FILE_TYPE, BLOCK_TRANSFER_MODE, CARRIAGE_CONTROL_TEXT_FORMAT, COMPRESSED_TRANSFER_MODE, DEFAULT_DATA_PORT, DEFAULT_PORT, EBCDIC_FILE_TYPE, FILE_STRUCTURE, IMAGE_FILE_TYPE, LOCAL_FILE_TYPE, NON_PRINT_TEXT_FORMAT, PAGE_STRUCTURE, RECORD_STRUCTURE, STREAM_TRANSFER_MODE, TELNET_TEXT_FORMAT |
Fields inherited from class com.oroinc.net.SocketClient |
_defaultPort_, _input_, _isConnected_, _output_, _socket_, _socketFactory_, _timeout_, NETASCII_EOL |
Constructor Summary | |
FTPClient()
Default FTPClient constructor. |
Method Summary | |
protected void |
_connectAction_()
Handles special connection requirements. |
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(java.lang.String remote,
java.io.InputStream local)
Appends to a file on the server with the given name, taking input from the given InputStream. |
java.io.OutputStream |
appendFileStream(java.lang.String remote)
Returns an OutputStream through which data can be written to append to a file on the server with the given name. |
boolean |
changeToParentDirectory()
Change to the parent directory of the current working directory. |
boolean |
changeWorkingDirectory(java.lang.String pathname)
Change the current working directory of the FTP session. |
boolean |
completePendingCommand()
There are a few FTPClient methods that do not complete the entire sequence of FTP commands to complete a transaction. |
boolean |
deleteFile(java.lang.String pathname)
Deletes a file on the FTP server. |
void |
disconnect()
Closes the connection to the FTP server and restores connection parameters to the default values. |
void |
enterLocalActiveMode()
Set the current data connection mode to ACTIVE_LOCAL_DATA_CONNECTION_MODE . |
void |
enterLocalPassiveMode()
Set the current data connection mode to PASSIVE_LOCAL_DATA_CONNECTION_MODE . |
boolean |
enterRemoteActiveMode(java.net.InetAddress host,
int port)
Set the current data connection mode to ACTIVE_REMOTE_DATA_CONNECTION . |
boolean |
enterRemotePassiveMode()
Set the current data connection mode to PASSIVE_REMOTE_DATA_CONNECTION_MODE . |
int |
getDataConnectionMode()
Returns the current data connection mode (one of the _DATA_CONNECTION_MODE constants. |
java.lang.String |
getPassiveHost()
Returns the hostname or IP address (in the form of a string) returned by the server when entering passive mode. |
int |
getPassivePort()
If in passive mode, returns the data port of the passive host. |
java.lang.String |
getStatus()
Issue the FTP STAT command to the server. |
java.lang.String |
getStatus(java.lang.String pathname)
Issue the FTP STAT command to the server for a given pathname. |
java.lang.String |
getSystemName()
Fetches the system type name from the server and returns the string. |
boolean |
isRemoteVerificationEnabled()
Return whether or not verification of the remote host participating in data connections is enabled. |
FTPFile[] |
listFiles()
Using the DefaultFTPFileListParser , obtain a list of
file information for the current working directory. |
FTPFile[] |
listFiles(FTPFileListParser parser)
Using a programmer specified FTPFileListParser ,
obtain a list of file information for the current working directory. |
FTPFile[] |
listFiles(FTPFileListParser parser,
java.lang.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(java.lang.String pathname)
Using the DefaultFTPFileListParser , obtain a list of
file information
for a directory or information for just a single file. |
java.lang.String |
listHelp()
Fetches the system help information from the server and returns the full string. |
java.lang.String |
listHelp(java.lang.String command)
Fetches the help information for a given command from the server and returns the full string. |
java.lang.String[] |
listNames()
Obtain a list of filenames in the current working directory This information is obtained through the NLST command. |
java.lang.String[] |
listNames(java.lang.String pathname)
Obtain a list of filenames in a directory (or just the name of a given file, which is not particularly useful). |
boolean |
login(java.lang.String username,
java.lang.String password)
Login to the FTP server using the provided username and password. |
boolean |
login(java.lang.String username,
java.lang.String password,
java.lang.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(java.lang.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). |
java.lang.String |
printWorkingDirectory()
Returns the pathname of the current working directory. |
boolean |
remoteAppend(java.lang.String filename)
Initiate a server to server file transfer. |
boolean |
remoteRetrieve(java.lang.String filename)
Initiate a server to server file transfer. |
boolean |
remoteStore(java.lang.String filename)
Initiate a server to server file transfer. |
boolean |
remoteStoreUnique()
Initiate a server to server file transfer. |
boolean |
remoteStoreUnique(java.lang.String filename)
Initiate a server to server file transfer. |
boolean |
removeDirectory(java.lang.String pathname)
Removes a directory on the FTP server (if empty). |
boolean |
rename(java.lang.String from,
java.lang.String to)
Renames a remote file. |
boolean |
restart(long offset)
Restart a STREAM_TRANSFER_MODE file transfer starting
from the given offset. |
boolean |
retrieveFile(java.lang.String remote,
java.io.OutputStream local)
Retrieves a named file from the server and writes it to the given OutputStream. |
java.io.InputStream |
retrieveFileStream(java.lang.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(java.lang.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 |
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. |
boolean |
storeFile(java.lang.String remote,
java.io.InputStream local)
Stores a file on the server using the given name and taking input from the given InputStream. |
java.io.OutputStream |
storeFileStream(java.lang.String remote)
Returns an OutputStream through which data can be written to store a file on the server using the given name. |
boolean |
storeUniqueFile(java.io.InputStream local)
Stores a file on the server using a unique name assigned by the server and taking input from the given InputStream. |
boolean |
storeUniqueFile(java.lang.String remote,
java.io.InputStream local)
Stores a file on the server using a unique name derived from the given name and taking input from the given InputStream. |
java.io.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. |
java.io.OutputStream |
storeUniqueFileStream(java.lang.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. |
boolean |
structureMount(java.lang.String pathname)
Issue the FTP SMNT command. |
Methods inherited from class com.oroinc.net.ftp.FTP |
abor, acct, addProtocolCommandListener, allo, allo, appe, cdup, cwd, dele, getReply, getReplyCode, getReplyString, getReplyStrings, help, help, list, list, mkd, mode, nlst, nlst, noop, pass, pasv, port, pwd, quit, rein, removeProtocolCommandistener, rest, retr, rmd, rnfr, rnto, sendCommand, sendCommand, sendCommand, sendCommand, site, smnt, stat, stat, stor, stou, stou, stru, syst, type, type, user |
Methods inherited from class com.oroinc.net.telnet.TelnetClient |
getInputStream, getOutputStream |
Methods inherited from class com.oroinc.net.SocketClient |
connect, connect, connect, connect, connect, connect, getDefaultPort, getDefaultTimeout, getLocalAddress, getLocalPort, getRemoteAddress, getRemotePort, getSoLinger, getSoTimeout, getTcpNoDelay, isConnected, setDefaultPort, setDefaultTimeout, setSocketFactory, setSoLinger, setSoTimeout, setTcpNoDelay, verifyRemote |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
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
Constructor Detail |
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
.Method Detail |
protected void _connectAction_() throws java.io.IOException
TelnetClient
_connectAction_
in class FTP
com.oroinc.net.telnet.TelnetClient
java.io.IOException
- If an error occurs during connection setup.public void setDataTimeout(int timeout)
timeout
- The default timeout in milliseconds that is used when
opening a data connection socket.public void disconnect() throws java.io.IOException
disconnect
in class FTP
java.io.IOException
- If an error occurs while disconnecting.public void setRemoteVerificationEnabled(boolean enable)
enable
- True to enable verification, false to disable verification.public boolean isRemoteVerificationEnabled()
public boolean login(java.lang.String username, java.lang.String password) throws java.io.IOException
username
- The username to login under.password
- The password to use.FTPConnectionClosedException
- If the FTP server prematurely closes the connection as a result
of the client being idle or some other reason causing the server
to send FTP reply code 421. This exception may be caught either
as an IOException or independently as itself.java.io.IOException
- If an I/O error occurs while either sending a
command to the server or receiving a reply from the server.public boolean login(java.lang.String username, java.lang.String password, java.lang.String account) throws java.io.IOException
username
- The username to login under.password
- The password to use.account
- The account to use.FTPConnectionClosedException
- If the FTP server prematurely closes the connection as a result
of the client being idle or some other reason causing the server
to send FTP reply code 421. This exception may be caught either
as an IOException or independently as itself.java.io.IOException
- If an I/O error occurs while either sending a
command to the server or receiving a reply from the server.public boolean logout() throws java.io.IOException
FTPConnectionClosedException
- If the FTP server prematurely closes the connection as a result
of the client being idle or some other reason causing the server
to send FTP reply code 421. This exception may be caught either
as an IOException or independently as itself.java.io.IOException
- If an I/O error occurs while either sending a
command to the server or receiving a reply from the server.public boolean changeWorkingDirectory(java.lang.String pathname) throws java.io.IOException
pathname
- The new current working directory.FTPConnectionClosedException
- If the FTP server prematurely closes the connection as a result
of the client being idle or some other reason causing the server
to send FTP reply code 421. This exception may be caught either
as an IOException or independently as itself.java.io.IOException
- If an I/O error occurs while either sending a
command to the server or receiving a reply from the server.public boolean changeToParentDirectory() throws java.io.IOException
FTPConnectionClosedException
- If the FTP server prematurely closes the connection as a result
of the client being idle or some other reason causing the server
to send FTP reply code 421. This exception may be caught either
as an IOException or independently as itself.java.io.IOException
- If an I/O error occurs while either sending a
command to the server or receiving a reply from the server.public boolean structureMount(java.lang.String pathname) throws java.io.IOException
pathname
- The pathname to mount.FTPConnectionClosedException
- If the FTP server prematurely closes the connection as a result
of the client being idle or some other reason causing the server
to send FTP reply code 421. This exception may be caught either
as an IOException or independently as itself.java.io.IOException
- If an I/O error occurs while either sending a
command to the server or receiving a reply from the server.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(java.net.InetAddress host, int port) throws java.io.IOException
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.
host
- The passive mode server accepting connections for data
transfers.port
- The passive mode server's data port.FTPConnectionClosedException
- If the FTP server prematurely closes the connection as a result
of the client being idle or some other reason causing the server
to send FTP reply code 421. This exception may be caught either
as an IOException or independently as itself.java.io.IOException
- If an I/O error occurs while either sending a
command to the server or receiving a reply from the server.public boolean enterRemotePassiveMode() throws java.io.IOException
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. This exception may be caught either
as an IOException or independently as itself.java.io.IOException
- If an I/O error occurs while either sending a
command to the server or receiving a reply from the server.public java.lang.String getPassiveHost()
public int getPassivePort()
public int getDataConnectionMode()
_DATA_CONNECTION_MODE
constants.
_DATA_CONNECTION_MODE
constants.public boolean setFileType(int fileType) throws java.io.IOException
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.
fileType
- The _FILE_TYPE
constant indcating the
type of file.FTPConnectionClosedException
- If the FTP server prematurely closes the connection as a result
of the client being idle or some other reason causing the server
to send FTP reply code 421. This exception may be caught either
as an IOException or independently as itself.java.io.IOException
- 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) throws java.io.IOException
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.
fileType
- The _FILE_TYPE
constant indcating the
type of file.formatOrByteSize
- The format of the file (one of the
_FORMAT
constants. In the case of
LOCAL_FILE_TYPE
, the byte size.
FTPConnectionClosedException
- If the FTP server prematurely closes the connection as a result
of the client being idle or some other reason causing the server
to send FTP reply code 421. This exception may be caught either
as an IOException or independently as itself.java.io.IOException
- If an I/O error occurs while either sending a
command to the server or receiving a reply from the server.public boolean setFileStructure(int structure) throws java.io.IOException
FTP.FILE_STRUCTURE
if this method is never called.
structure
- The structure of the file (one of the FTP class
_STRUCTURE
constants).FTPConnectionClosedException
- If the FTP server prematurely closes the connection as a result
of the client being idle or some other reason causing the server
to send FTP reply code 421. This exception may be caught either
as an IOException or independently as itself.java.io.IOException
- 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) throws java.io.IOException
FTP.STREAM_TRANSFER_MODE
if this method is never called.
mode
- The new transfer mode to use (one of the FTP class
_TRANSFER_MODE
constants).FTPConnectionClosedException
- If the FTP server prematurely closes the connection as a result
of the client being idle or some other reason causing the server
to send FTP reply code 421. This exception may be caught either
as an IOException or independently as itself.java.io.IOException
- If an I/O error occurs while either sending a
command to the server or receiving a reply from the server.public boolean remoteRetrieve(java.lang.String filename) throws java.io.IOException
filename
- The name of the file to retrieve.FTPConnectionClosedException
- If the FTP server prematurely closes the connection as a result
of the client being idle or some other reason causing the server
to send FTP reply code 421. This exception may be caught either
as an IOException or independently as itself.java.io.IOException
- If an I/O error occurs while either sending a
command to the server or receiving a reply from the server.public boolean remoteStore(java.lang.String filename) throws java.io.IOException
remoteRetrieve
issued to it by another
FTPClient.
filename
- The name to call the file that is to be stored.FTPConnectionClosedException
- If the FTP server prematurely closes the connection as a result
of the client being idle or some other reason causing the server
to send FTP reply code 421. This exception may be caught either
as an IOException or independently as itself.java.io.IOException
- If an I/O error occurs while either sending a
command to the server or receiving a reply from the server.public boolean remoteStoreUnique(java.lang.String filename) throws java.io.IOException
remoteRetrieve
issued
to it by another FTPClient.
filename
- The name on which to base the filename of the file
that is to be stored.FTPConnectionClosedException
- If the FTP server prematurely closes the connection as a result
of the client being idle or some other reason causing the server
to send FTP reply code 421. This exception may be caught either
as an IOException or independently as itself.java.io.IOException
- If an I/O error occurs while either sending a
command to the server or receiving a reply from the server.public boolean remoteStoreUnique() throws java.io.IOException
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. This exception may be caught either
as an IOException or independently as itself.java.io.IOException
- If an I/O error occurs while either sending a
command to the server or receiving a reply from the server.public boolean remoteAppend(java.lang.String filename) throws java.io.IOException
remoteRetrieve
issued to it by another FTPClient.
filename
- The name of the file to be appended to, or if the
file does not exist, the name to call the file being stored.
FTPConnectionClosedException
- If the FTP server prematurely closes the connection as a result
of the client being idle or some other reason causing the server
to send FTP reply code 421. This exception may be caught either
as an IOException or independently as itself.java.io.IOException
- If an I/O error occurs while either sending a
command to the server or receiving a reply from the server.public boolean completePendingCommand() throws java.io.IOException
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); }
FTPConnectionClosedException
- If the FTP server prematurely closes the connection as a result
of the client being idle or some other reason causing the server
to send FTP reply code 421. This exception may be caught either
as an IOException or independently as itself.java.io.IOException
- If an I/O error occurs while either sending a
command to the server or receiving a reply from the server.public boolean retrieveFile(java.lang.String remote, java.io.OutputStream local) throws java.io.IOException
remote
- The name of the remote file.local
- The local OutputStream to which to write the file.FTPConnectionClosedException
- If the FTP server prematurely closes the connection as a result
of the client being idle or some other reason causing the server
to send FTP reply code 421. This exception may be caught either
as an IOException or independently as itself.CopyStreamException
- If an I/O error occurs while actually
transferring the file. The CopyStreamException allows you to
determine the number of bytes transferred and the IOException
causing the error. This exception may be caught either
as an IOException or independently as itself.java.io.IOException
- If an I/O error occurs while either sending a
command to the server or receiving a reply from the server.public java.io.InputStream retrieveFileStream(java.lang.String remote) throws java.io.IOException
remote
- The name of the remote file.FTPConnectionClosedException
- If the FTP server prematurely closes the connection as a result
of the client being idle or some other reason causing the server
to send FTP reply code 421. This exception may be caught either
as an IOException or independently as itself.java.io.IOException
- If an I/O error occurs while either sending a
command to the server or receiving a reply from the server.public boolean storeFile(java.lang.String remote, java.io.InputStream local) throws java.io.IOException
remote
- The name to give the remote file.local
- The local InputStream from which to read the file.FTPConnectionClosedException
- If the FTP server prematurely closes the connection as a result
of the client being idle or some other reason causing the server
to send FTP reply code 421. This exception may be caught either
as an IOException or independently as itself.CopyStreamException
- If an I/O error occurs while actually
transferring the file. The CopyStreamException allows you to
determine the number of bytes transferred and the IOException
causing the error. This exception may be caught either
as an IOException or independently as itself.java.io.IOException
- If an I/O error occurs while either sending a
command to the server or receiving a reply from the server.public java.io.OutputStream storeFileStream(java.lang.String remote) throws java.io.IOException
remote
- The name to give the remote file.FTPConnectionClosedException
- If the FTP server prematurely closes the connection as a result
of the client being idle or some other reason causing the server
to send FTP reply code 421. This exception may be caught either
as an IOException or independently as itself.java.io.IOException
- If an I/O error occurs while either sending a
command to the server or receiving a reply from the server.public boolean appendFile(java.lang.String remote, java.io.InputStream local) throws java.io.IOException
remote
- The name of the remote file.local
- The local InputStream from which to read the data to
be appended to the remote file.FTPConnectionClosedException
- If the FTP server prematurely closes the connection as a result
of the client being idle or some other reason causing the server
to send FTP reply code 421. This exception may be caught either
as an IOException or independently as itself.CopyStreamException
- If an I/O error occurs while actually
transferring the file. The CopyStreamException allows you to
determine the number of bytes transferred and the IOException
causing the error. This exception may be caught either
as an IOException or independently as itself.java.io.IOException
- If an I/O error occurs while either sending a
command to the server or receiving a reply from the server.public java.io.OutputStream appendFileStream(java.lang.String remote) throws java.io.IOException
remote
- The name of the remote file.FTPConnectionClosedException
- If the FTP server prematurely closes the connection as a result
of the client being idle or some other reason causing the server
to send FTP reply code 421. This exception may be caught either
as an IOException or independently as itself.java.io.IOException
- If an I/O error occurs while either sending a
command to the server or receiving a reply from the server.public boolean storeUniqueFile(java.lang.String remote, java.io.InputStream local) throws java.io.IOException
remote
- The name on which to base the unique name given to
the remote file.local
- The local InputStream from which to read the file.FTPConnectionClosedException
- If the FTP server prematurely closes the connection as a result
of the client being idle or some other reason causing the server
to send FTP reply code 421. This exception may be caught either
as an IOException or independently as itself.CopyStreamException
- If an I/O error occurs while actually
transferring the file. The CopyStreamException allows you to
determine the number of bytes transferred and the IOException
causing the error. This exception may be caught either
as an IOException or independently as itself.java.io.IOException
- If an I/O error occurs while either sending a
command to the server or receiving a reply from the server.public java.io.OutputStream storeUniqueFileStream(java.lang.String remote) throws java.io.IOException
remote
- The name on which to base the unique name given to
the remote file.FTPConnectionClosedException
- If the FTP server prematurely closes the connection as a result
of the client being idle or some other reason causing the server
to send FTP reply code 421. This exception may be caught either
as an IOException or independently as itself.java.io.IOException
- If an I/O error occurs while either sending a
command to the server or receiving a reply from the server.public boolean storeUniqueFile(java.io.InputStream local) throws java.io.IOException
remote
- The name to give the remote file.local
- The local InputStream from which to read the file.FTPConnectionClosedException
- If the FTP server prematurely closes the connection as a result
of the client being idle or some other reason causing the server
to send FTP reply code 421. This exception may be caught either
as an IOException or independently as itself.CopyStreamException
- If an I/O error occurs while actually
transferring the file. The CopyStreamException allows you to
determine the number of bytes transferred and the IOException
causing the error. This exception may be caught either
as an IOException or independently as itself.java.io.IOException
- If an I/O error occurs while either sending a
command to the server or receiving a reply from the server.public java.io.OutputStream storeUniqueFileStream() throws java.io.IOException
remote
- The name to give the remote file.FTPConnectionClosedException
- If the FTP server prematurely closes the connection as a result
of the client being idle or some other reason causing the server
to send FTP reply code 421. This exception may be caught either
as an IOException or independently as itself.java.io.IOException
- 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) throws java.io.IOException
bytes
- The number of bytes which the server should allocate.FTPConnectionClosedException
- If the FTP server prematurely closes the connection as a result
of the client being idle or some other reason causing the server
to send FTP reply code 421. This exception may be caught either
as an IOException or independently as itself.java.io.IOException
- 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) throws java.io.IOException
bytes
- The number of bytes which the server should allocate.bytes
- The size of a file record.FTPConnectionClosedException
- If the FTP server prematurely closes the connection as a result
of the client being idle or some other reason causing the server
to send FTP reply code 421. This exception may be caught either
as an IOException or independently as itself.java.io.IOException
- If an I/O error occurs while either sending a
command to the server or receiving a reply from the server.public boolean restart(long offset) throws java.io.IOException
STREAM_TRANSFER_MODE
file transfer starting
from the given offset. This will only work on FTP servers supporting
the REST comand for the stream transfer mode. However, most FTP
servers support this. Any subsequent file transfer will start
reading or writing the remote file from the indicated offset.
offset
- The offset into the remote file at which to start the
next file transfer.FTPConnectionClosedException
- If the FTP server prematurely closes the connection as a result
of the client being idle or some other reason causing the server
to send FTP reply code 421. This exception may be caught either
as an IOException or independently as itself.java.io.IOException
- If an I/O error occurs while either sending a
command to the server or receiving a reply from the server.public boolean rename(java.lang.String from, java.lang.String to) throws java.io.IOException
from
- The name of the remote file to rename.to
- The new name of the remote file.FTPConnectionClosedException
- If the FTP server prematurely closes the connection as a result
of the client being idle or some other reason causing the server
to send FTP reply code 421. This exception may be caught either
as an IOException or independently as itself.java.io.IOException
- If an I/O error occurs while either sending a
command to the server or receiving a reply from the server.public boolean abort() throws java.io.IOException
FTPConnectionClosedException
- If the FTP server prematurely closes the connection as a result
of the client being idle or some other reason causing the server
to send FTP reply code 421. This exception may be caught either
as an IOException or independently as itself.java.io.IOException
- If an I/O error occurs while either sending a
command to the server or receiving a reply from the server.public boolean deleteFile(java.lang.String pathname) throws java.io.IOException
pathname
- The pathname of the file to be deleted.FTPConnectionClosedException
- If the FTP server prematurely closes the connection as a result
of the client being idle or some other reason causing the server
to send FTP reply code 421. This exception may be caught either
as an IOException or independently as itself.java.io.IOException
- If an I/O error occurs while either sending a
command to the server or receiving a reply from the server.public boolean removeDirectory(java.lang.String pathname) throws java.io.IOException
pathname
- The pathname of the directory to remove.FTPConnectionClosedException
- If the FTP server prematurely closes the connection as a result
of the client being idle or some other reason causing the server
to send FTP reply code 421. This exception may be caught either
as an IOException or independently as itself.java.io.IOException
- If an I/O error occurs while either sending a
command to the server or receiving a reply from the server.public boolean makeDirectory(java.lang.String pathname) throws java.io.IOException
pathname
- The pathname of the directory to create.FTPConnectionClosedException
- If the FTP server prematurely closes the connection as a result
of the client being idle or some other reason causing the server
to send FTP reply code 421. This exception may be caught either
as an IOException or independently as itself.java.io.IOException
- If an I/O error occurs while either sending a
command to the server or receiving a reply from the server.public java.lang.String printWorkingDirectory() throws java.io.IOException
FTPConnectionClosedException
- If the FTP server prematurely closes the connection as a result
of the client being idle or some other reason causing the server
to send FTP reply code 421. This exception may be caught either
as an IOException or independently as itself.java.io.IOException
- If an I/O error occurs while either sending a
command to the server or receiving a reply from the server.public boolean sendSiteCommand(java.lang.String arguments) throws java.io.IOException
argument
- The site specific command and 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. This exception may be caught either
as an IOException or independently as itself.java.io.IOException
- If an I/O error occurs while either sending a
command to the server or receiving a reply from the server.public java.lang.String getSystemName() throws java.io.IOException
FTPConnectionClosedException
- If the FTP server prematurely closes the connection as a result
of the client being idle or some other reason causing the server
to send FTP reply code 421. This exception may be caught either
as an IOException or independently as itself.java.io.IOException
- If an I/O error occurs while either sending a
command to the server or receiving a reply from the server.public java.lang.String listHelp() throws java.io.IOException
FTPConnectionClosedException
- If the FTP server prematurely closes the connection as a result
of the client being idle or some other reason causing the server
to send FTP reply code 421. This exception may be caught either
as an IOException or independently as itself.java.io.IOException
- If an I/O error occurs while either sending a
command to the server or receiving a reply from the server.public java.lang.String listHelp(java.lang.String command) throws java.io.IOException
The
- command on which to ask for help.FTPConnectionClosedException
- If the FTP server prematurely closes the connection as a result
of the client being idle or some other reason causing the server
to send FTP reply code 421. This exception may be caught either
as an IOException or independently as itself.java.io.IOException
- If an I/O error occurs while either sending a
command to the server or receiving a reply from the server.public boolean sendNoOp() throws java.io.IOException
FTPConnectionClosedException
- If the FTP server prematurely closes the connection as a result
of the client being idle or some other reason causing the server
to send FTP reply code 421. This exception may be caught either
as an IOException or independently as itself.java.io.IOException
- If an I/O error occurs while either sending a
command to the server or receiving a reply from the server.public java.lang.String[] listNames(java.lang.String pathname) throws java.io.IOException
pathname
- The file or directory to list.FTPConnectionClosedException
- If the FTP server prematurely closes the connection as a result
of the client being idle or some other reason causing the server
to send FTP reply code 421. This exception may be caught either
as an IOException or independently as itself.java.io.IOException
- If an I/O error occurs while either sending a
command to the server or receiving a reply from the server.public java.lang.String[] listNames() throws java.io.IOException
FTPConnectionClosedException
- If the FTP server prematurely closes the connection as a result
of the client being idle or some other reason causing the server
to send FTP reply code 421. This exception may be caught either
as an IOException or independently as itself.java.io.IOException
- 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, java.lang.String pathname) throws java.io.IOException
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.
parser
- The FTPFileListParser
that should be
used to parse the server file listing.pathname
- The file or directory to list. parser
parameter.FTPConnectionClosedException
- If the FTP server prematurely closes the connection as a result
of the client being idle or some other reason causing the server
to send FTP reply code 421. This exception may be caught either
as an IOException or independently as itself.java.io.IOException
- 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) throws java.io.IOException
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.
parser
- The FTPFileListParser
that should be
used to parse the server file listing. parser
parameter.FTPConnectionClosedException
- If the FTP server prematurely closes the connection as a result
of the client being idle or some other reason causing the server
to send FTP reply code 421. This exception may be caught either
as an IOException or independently as itself.java.io.IOException
- If an I/O error occurs while either sending a
command to the server or receiving a reply from the server.public FTPFile[] listFiles(java.lang.String pathname) throws java.io.IOException
DefaultFTPFileListParser
, obtain a list of
file information
for a directory or information for just a single file. This information
is obtained through the LIST command. If the given
pathname is a directory and contains no files, null
is
returned, otherwise an array of FTPFile
instances
representing the files in the directory is returned.
If the pathname corresponds to a file, only the information for that
file will be contained in the array (which will be of length 1). 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.
pathname
- The file or directory to list.FTPConnectionClosedException
- If the FTP server prematurely closes the connection as a result
of the client being idle or some other reason causing the server
to send FTP reply code 421. This exception may be caught either
as an IOException or independently as itself.java.io.IOException
- If an I/O error occurs while either sending a
command to the server or receiving a reply from the server.public FTPFile[] listFiles() throws java.io.IOException
DefaultFTPFileListParser
, obtain a list of
file information for the current working directory. This information
is obtained through the LIST command. If the given
current directory contains no files null is returned, otherwise an
array of FTPFile
instances representing the files in the
directory is returned.
FTPConnectionClosedException
- If the FTP server prematurely closes the connection as a result
of the client being idle or some other reason causing the server
to send FTP reply code 421. This exception may be caught either
as an IOException or independently as itself.java.io.IOException
- If an I/O error occurs while either sending a
command to the server or receiving a reply from the server.public java.lang.String getStatus() throws java.io.IOException
FTPConnectionClosedException
- If the FTP server prematurely closes the connection as a result
of the client being idle or some other reason causing the server
to send FTP reply code 421. This exception may be caught either
as an IOException or independently as itself.java.io.IOException
- If an I/O error occurs while either sending a
command to the server or receiving a reply from the server.public java.lang.String getStatus(java.lang.String pathname) throws java.io.IOException
FTPConnectionClosedException
- If the FTP server prematurely closes the connection as a result
of the client being idle or some other reason causing the server
to send FTP reply code 421. This exception may be caught either
as an IOException or independently as itself.java.io.IOException
- If an I/O error occurs while either sending a
command to the server or receiving a reply from the server.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |