public abstract class AFTPClient extends Object
Modifier and Type | Field and Description |
---|---|
static int |
FILE_TYPE_BINARY |
static int |
FILE_TYPE_TEXT |
Constructor and Description |
---|
AFTPClient() |
Modifier and Type | Method and Description |
---|---|
abstract boolean |
changeWorkingDirectory(String pathname)
Change the current working directory of the FTP session.
|
abstract void |
connect()
Opens a Socket connected to a remote host at the specified port and
originating from the current host at a system assigned port.
|
abstract boolean |
deleteFile(String pathname)
Deletes a file on the FTP server.
|
abstract boolean |
directoryExists(String pathname) |
abstract void |
disconnect()
Closes the connection to the FTP server and restores
connection parameters to the default values.
|
abstract void |
enterLocalActiveMode()
Set the current data connection mode to
ACTIVE_LOCAL_DATA_CONNECTION_MODE . |
abstract void |
enterLocalPassiveMode()
Set the current data connection mode to
PASSIVE_LOCAL_DATA_CONNECTION_MODE . |
abstract int |
getDataConnectionMode()
Returns the current data connection mode (one of the
_DATA_CONNECTION_MODE constants. |
static AFTPClient |
getInstance(boolean secure,
InetAddress host,
int port,
String username,
String password,
String fingerprint,
boolean stopOnError) |
abstract String |
getPrefix() |
abstract InetAddress |
getRemoteAddress() |
abstract int |
getReplyCode()
Returns the integer value of the reply code of the last FTP reply.
|
abstract String |
getReplyString()
Returns the entire text of the last FTP server response exactly
as it was received, including all end of line markers in NETASCII
format.
|
abstract void |
init(InetAddress host,
int port,
String username,
String password,
String fingerprint,
boolean stopOnError) |
abstract boolean |
isConnected()
Returns true if the client is currently connected to a server.
|
abstract boolean |
isPositiveCompletion()
Determine if a reply code is a positive completion response.
|
abstract org.apache.commons.net.ftp.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.
|
abstract 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).
|
abstract String |
printWorkingDirectory()
Returns the pathname of the current working directory.
|
abstract int |
quit()
A convenience method to send the FTP QUIT command to the server,
receive the reply, and return the reply code.
|
abstract boolean |
removeDirectory(String pathname)
Removes a directory on the FTP server (if empty).
|
abstract boolean |
rename(String from,
String to)
Renames a remote file.
|
abstract boolean |
retrieveFile(String remote,
OutputStream local)
Retrieves a named file from the server and writes it to the given
OutputStream.
|
abstract boolean |
setFileType(int fileType)
Sets the file type to be transferred.
|
abstract void |
setTimeout(int timeout)
timeout in milli seconds
|
abstract boolean |
storeFile(String remote,
InputStream local)
Stores a file on the server using the given name and taking input
from the given InputStream.
|
public static final int FILE_TYPE_BINARY
public static final int FILE_TYPE_TEXT
public AFTPClient()
public static AFTPClient getInstance(boolean secure, InetAddress host, int port, String username, String password, String fingerprint, boolean stopOnError) throws SocketException, IOException
SocketException
IOException
public abstract boolean rename(String from, String to) throws 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.IOException
- If an I/O error occurs while either sending a
command to the server or receiving a reply from the server.FTPException
public abstract int getReplyCode()
connect
is of type void.
public abstract String getReplyString()
public abstract boolean changeWorkingDirectory(String pathname) throws 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.IOException
- If an I/O error occurs while either sending a
command to the server or receiving a reply from the server.public abstract boolean makeDirectory(String pathname) throws 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.IOException
- If an I/O error occurs while either sending a
command to the server or receiving a reply from the server.public abstract org.apache.commons.net.ftp.FTPFile[] listFiles(String pathname) throws IOException
This information is obtained through the LIST command. The contents of
the returned array is determined by the FTPFileEntryParser
used.
pathname
- The file or directory to list. Since the server may
or may not expand glob expressions, using them here
is not recommended and may well cause this method to
fail.
Also, some servers treat a leading '-' as being an option.
To avoid this interpretation, use an absolute pathname
or prefix the pathname with ./ (unix style servers).
Some servers may support "--" as meaning end of options,
in which case "-- -xyz" should work.FTPConnectionClosedException
- If the FTP server prematurely closes the connection
as a result of the client being idle or some other
reason causing the server to send FTP reply code 421.
This exception may be caught either as an IOException
or independently as itself.IOException
- If an I/O error occurs while either sending a
command to the server or receiving a reply
from the server.org.apache.commons.net.ftp.parser.ParserInitializationException
- Thrown if the parserKey parameter cannot be
resolved by the selected parser factory.
In the DefaultFTPEntryParserFactory, this will
happen when parserKey is neither
the fully qualified class name of a class
implementing the interface
org.apache.commons.net.ftp.FTPFileEntryParser
nor a string containing one of the recognized keys
mapping to such a parser or if class loader
security issues prevent its being loaded.public abstract boolean removeDirectory(String pathname) throws IOException
pathname
- The pathname of the directory to remove.recursive
- if true it also can deleteFTPConnectionClosedException
- If the FTP server prematurely closes the connection as a result
of the client being idle or some other reason causing the server
to send FTP reply code 421. This exception may be caught either
as an IOException or independently as itself.IOException
- If an I/O error occurs while either sending a
command to the server or receiving a reply from the server.public abstract boolean setFileType(int fileType) throws IOException
FTP.ASCII_FILE_TYPE
, FTP.BINARY_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.
N.B. currently calling any connect method will reset the type to FTP.ASCII_FILE_TYPE.
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.IOException
- If an I/O error occurs while either sending a
command to the server or receiving a reply from the server.public abstract boolean retrieveFile(String remote, OutputStream local) throws IOException
Note: if you have used #setRestartOffset(long)
,
the file data will start from the selected offset.
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.org.apache.commons.net.io.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.IOException
- If an I/O error occurs while either sending a
command to the server or receiving a reply from the server.public abstract boolean storeFile(String remote, InputStream local) throws 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.org.apache.commons.net.io.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.IOException
- If an I/O error occurs while either sending a
command to the server or receiving a reply from the server.public abstract boolean deleteFile(String pathname) throws 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.IOException
- If an I/O error occurs while either sending a
command to the server or receiving a reply from the server.public abstract String printWorkingDirectory() throws 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.IOException
- If an I/O error occurs while either sending a
command to the server or receiving a reply from the server.public abstract InetAddress getRemoteAddress()
Socket.getInetAddress()
NullPointerException
- if the socket is not currently openpublic abstract boolean isConnected()
Delegates to Socket.isConnected()
public abstract int quit() throws 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.IOException
- If an I/O error occurs while either sending the
command or receiving the server reply.public abstract void disconnect() throws IOException
IOException
- If an error occurs while disconnecting.public abstract void setTimeout(int timeout)
timeout
- public abstract int getDataConnectionMode()
_DATA_CONNECTION_MODE
constants.
_DATA_CONNECTION_MODE
constants.public abstract void enterLocalPassiveMode()
PASSIVE_LOCAL_DATA_CONNECTION_MODE
. Use this
method only for data transfers between the client and server.
This method causes a PASV (or EPSV) 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()
N.B. currently calling any connect method will reset the mode to ACTIVE_LOCAL_DATA_CONNECTION_MODE.
public abstract 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 abstract void init(InetAddress host, int port, String username, String password, String fingerprint, boolean stopOnError) throws SocketException, IOException
SocketException
IOException
public abstract void connect() throws SocketException, IOException
_connectAction_()
is called to perform connection initialization actions.
host
- The remote host.port
- The port to connect to on the remote host.SocketException
- If the socket timeout could not be set.IOException
- If the socket could not be opened. In most
cases you will only want to catch IOException since SocketException is
derived from it.FTPException
public abstract boolean isPositiveCompletion()
reply
- The reply code to test.public abstract boolean directoryExists(String pathname) throws IOException
IOException
Copyright © 2015 Lucee