public class FTPConnection
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
protected static java.lang.String |
ABOR |
protected static java.lang.String |
ACCT |
protected static java.lang.String |
ALLO |
protected static java.lang.String |
APPE |
protected static java.lang.String |
AUTH |
protected static java.lang.String |
CCC |
protected static java.lang.String |
CDUP |
protected int |
connectionTimeout
The timeout when attempting to connect a socket.
|
protected static java.lang.String |
CWD |
protected boolean |
debug
If true, print debugging information.
|
protected static java.lang.String |
DELE |
protected gnu.inet.ftp.DTP |
dtp
The current data transfer process in use by this connection.
|
protected int |
fileStructure
The current file structure type.
|
static int |
FTP_DATA_PORT
The FTP data port.
|
static int |
FTP_PORT
The default FTP transmission control port.
|
protected static java.lang.String |
HELP |
protected LineInputStream |
in
The socket input stream.
|
protected static java.lang.String |
LIST |
protected static java.lang.String |
MKD |
protected static java.lang.String |
MODE |
static int |
MODE_BLOCK |
static int |
MODE_COMPRESSED |
static int |
MODE_STREAM |
protected static java.lang.String |
NLST |
protected static java.lang.String |
NOOP |
protected CRLFOutputStream |
out
The socket output stream.
|
protected static java.lang.String |
PASS |
protected boolean |
passive
If true, use passive mode.
|
protected static java.lang.String |
PASV |
protected static java.lang.String |
PBSZ |
protected static java.lang.String |
PORT |
protected static java.lang.String |
PROT |
protected static java.lang.String |
PWD |
protected static java.lang.String |
QUIT |
protected static java.lang.String |
REIN |
protected int |
representationType
The current representation type.
|
protected static java.lang.String |
REST |
protected static java.lang.String |
RETR |
protected static java.lang.String |
RMD |
protected static java.lang.String |
RNFR |
protected static java.lang.String |
RNTO |
protected static java.lang.String |
SITE |
protected static java.lang.String |
SMNT |
protected java.net.Socket |
socket
The socket used to communicate with the server.
|
protected static java.lang.String |
STAT |
protected static java.lang.String |
STOR |
protected static java.lang.String |
STOU |
protected static java.lang.String |
STRU |
static int |
STRUCTURE_FILE |
static int |
STRUCTURE_PAGE |
static int |
STRUCTURE_RECORD |
protected static java.lang.String |
SYST |
protected int |
timeout
The read timeout on sockets.
|
protected static java.lang.String |
TLS |
protected int |
transferMode
The current transfer mode.
|
protected static java.lang.String |
TYPE |
static int |
TYPE_ASCII |
static int |
TYPE_BINARY |
static int |
TYPE_EBCDIC |
protected static java.lang.String |
USER |
Constructor and Description |
---|
FTPConnection(java.lang.String hostname)
Creates a new connection to the server using the default port.
|
FTPConnection(java.lang.String hostname,
int port)
Creates a new connection to the server.
|
FTPConnection(java.lang.String hostname,
int port,
int connectionTimeout,
int timeout,
boolean debug)
Creates a new connection to the server.
|
Modifier and Type | Method and Description |
---|---|
boolean |
abort()
Aborts the transfer in progress.
|
void |
allocate(long size)
This command may be required by some servers to reserve sufficient
storage to accommodate the new file to be transferred.
|
java.io.OutputStream |
append(java.lang.String filename)
Returns a stream for uploading a file.
|
boolean |
authenticate(java.lang.String username,
java.lang.String password)
Authenticate using the specified username and password.
|
boolean |
changeToParentDirectory()
Changes directory to the parent of the current working directory.
|
boolean |
changeWorkingDirectory(java.lang.String path)
Changes directory to the specified path.
|
boolean |
delete(java.lang.String filename)
Causes the file specified to be deleted at the server site.
|
int |
getFileStructure()
Returns the current file structure type.
|
int |
getRepresentationType()
Returns the current representation type of the transfer data.
|
protected FTPResponse |
getResponse()
Reads the next response from the server.
|
int |
getTransferMode()
Returns the current transfer mode.
|
java.lang.String |
getWorkingDirectory()
Returns the current working directory.
|
protected void |
initialiseDTP()
Initialise the data transfer process.
|
java.io.InputStream |
list(java.lang.String pathname)
Returns a listing of information about the specified pathname.
|
void |
logout()
Terminates the control connection.
|
boolean |
makeDirectory(java.lang.String pathname)
Causes the directory specified to be created at the server site.
|
java.util.List |
nameList(java.lang.String pathname)
Returns a directory listing.
|
void |
noop()
Does nothing.
|
protected FTPResponse |
readResponse()
Reads and parses the next response from the server.
|
void |
reinitialize()
Terminates an authenticated login.
|
boolean |
removeDirectory(java.lang.String pathname)
Causes the directory specified to be deleted.
|
boolean |
rename(java.lang.String oldName,
java.lang.String newName)
Renames a file.
|
java.io.InputStream |
retrieve(java.lang.String filename)
Retrieves the specified file.
|
protected void |
send(java.lang.String cmd)
Sends the specified command line to the server.
|
void |
setFileStructure(int structure)
Sets the desired file structure type.
|
void |
setPassive(boolean flag)
Set passive mode.
|
void |
setRepresentationType(int type)
Sets the desired representation type of the transfer data.
|
void |
setTransferMode(int mode)
Sets the desired transfer mode.
|
boolean |
starttls(boolean confidential)
Negotiates TLS over the current connection.
|
boolean |
starttls(boolean confidential,
javax.net.ssl.TrustManager tm)
Negotiates TLS over the current connection.
|
java.io.OutputStream |
store(java.lang.String filename)
Returns a stream for uploading a file.
|
java.lang.String |
system()
Returns the type of operating system at the server.
|
public static final int FTP_PORT
public static final int FTP_DATA_PORT
protected static final java.lang.String USER
protected static final java.lang.String PASS
protected static final java.lang.String ACCT
protected static final java.lang.String CWD
protected static final java.lang.String CDUP
protected static final java.lang.String SMNT
protected static final java.lang.String REIN
protected static final java.lang.String QUIT
protected static final java.lang.String PORT
protected static final java.lang.String PASV
protected static final java.lang.String TYPE
protected static final java.lang.String STRU
protected static final java.lang.String MODE
protected static final java.lang.String RETR
protected static final java.lang.String STOR
protected static final java.lang.String STOU
protected static final java.lang.String APPE
protected static final java.lang.String ALLO
protected static final java.lang.String REST
protected static final java.lang.String RNFR
protected static final java.lang.String RNTO
protected static final java.lang.String ABOR
protected static final java.lang.String DELE
protected static final java.lang.String RMD
protected static final java.lang.String MKD
protected static final java.lang.String PWD
protected static final java.lang.String LIST
protected static final java.lang.String NLST
protected static final java.lang.String SITE
protected static final java.lang.String SYST
protected static final java.lang.String STAT
protected static final java.lang.String HELP
protected static final java.lang.String NOOP
protected static final java.lang.String AUTH
protected static final java.lang.String PBSZ
protected static final java.lang.String PROT
protected static final java.lang.String CCC
protected static final java.lang.String TLS
public static final int TYPE_ASCII
public static final int TYPE_EBCDIC
public static final int TYPE_BINARY
public static final int STRUCTURE_FILE
public static final int STRUCTURE_RECORD
public static final int STRUCTURE_PAGE
public static final int MODE_STREAM
public static final int MODE_BLOCK
public static final int MODE_COMPRESSED
protected java.net.Socket socket
protected LineInputStream in
protected CRLFOutputStream out
protected int connectionTimeout
protected int timeout
protected boolean debug
protected gnu.inet.ftp.DTP dtp
protected int representationType
protected int fileStructure
protected int transferMode
protected boolean passive
public FTPConnection(java.lang.String hostname) throws java.net.UnknownHostException, java.io.IOException
hostname
- the hostname of the server to connect tojava.net.UnknownHostException
java.io.IOException
public FTPConnection(java.lang.String hostname, int port) throws java.net.UnknownHostException, java.io.IOException
hostname
- the hostname of the server to connect toport
- the port to connect to(if <=0, use default port)java.net.UnknownHostException
java.io.IOException
public FTPConnection(java.lang.String hostname, int port, int connectionTimeout, int timeout, boolean debug) throws java.net.UnknownHostException, java.io.IOException
hostname
- the hostname of the server to connect toport
- the port to connect to(if <=0, use default port)connectionTimeout
- the connection timeout, in millisecondstimeout
- the I/O timeout, in millisecondsdebug
- print debugging informationjava.net.UnknownHostException
java.io.IOException
public boolean authenticate(java.lang.String username, java.lang.String password) throws java.io.IOException
username
- the usernamepassword
- the optional passwordjava.io.IOException
public boolean starttls(boolean confidential) throws java.io.IOException
confidential
- whether to provide confidentiality for the
connectionjava.io.IOException
public boolean starttls(boolean confidential, javax.net.ssl.TrustManager tm) throws java.io.IOException
confidential
- whether to provide confidentiality for the
connectiontm
- the trust manager used to validate the server certificate.java.io.IOException
public boolean changeWorkingDirectory(java.lang.String path) throws java.io.IOException
path
- an absolute or relative pathnamejava.io.IOException
public boolean changeToParentDirectory() throws java.io.IOException
java.io.IOException
public void reinitialize() throws java.io.IOException
java.io.IOException
public void logout() throws java.io.IOException
java.io.IOException
protected void initialiseDTP() throws java.io.IOException
java.io.IOException
public void setPassive(boolean flag) throws java.io.IOException
flag
- true if we should use passive mode, false otherwisejava.io.IOException
public int getRepresentationType()
public void setRepresentationType(int type) throws java.io.IOException
type
- TYPE_ASCII, TYPE_EBCDIC, or TYPE_BINARYjava.io.IOException
public int getFileStructure()
public void setFileStructure(int structure) throws java.io.IOException
structure
- STRUCTURE_FILE, STRUCTURE_RECORD, or STRUCTURE_PAGEjava.io.IOException
public int getTransferMode()
public void setTransferMode(int mode) throws java.io.IOException
mode
- MODE_STREAM, MODE_BLOCK, or MODE_COMPRESSEDjava.io.IOException
public java.io.InputStream retrieve(java.lang.String filename) throws java.io.IOException
filename
- the filename of the file to retrievejava.io.IOException
public java.io.OutputStream store(java.lang.String filename) throws java.io.IOException
filename
- the name of the file to save the content asjava.io.IOException
public java.io.OutputStream append(java.lang.String filename) throws java.io.IOException
filename
- the name of the file to save the content asjava.io.IOException
public void allocate(long size) throws java.io.IOException
store
or
append
.size
- the number of bytes of storage to allocatejava.io.IOException
public boolean rename(java.lang.String oldName, java.lang.String newName) throws java.io.IOException
oldName
- the current name of the filenewName
- the new namejava.io.IOException
public boolean abort() throws java.io.IOException
java.io.IOException
public boolean delete(java.lang.String filename) throws java.io.IOException
filename
- the file to deletejava.io.IOException
public boolean removeDirectory(java.lang.String pathname) throws java.io.IOException
pathname
- the directory to deletejava.io.IOException
public boolean makeDirectory(java.lang.String pathname) throws java.io.IOException
pathname
- the directory to createjava.io.IOException
public java.lang.String getWorkingDirectory() throws java.io.IOException
java.io.IOException
public java.io.InputStream list(java.lang.String pathname) throws java.io.IOException
pathname
- the context pathname, or nulljava.io.IOException
public java.util.List nameList(java.lang.String pathname) throws java.io.IOException
pathname
- the directory pathname, or nulljava.io.IOException
public java.lang.String system() throws java.io.IOException
java.io.IOException
public void noop() throws java.io.IOException
java.io.IOException
protected void send(java.lang.String cmd) throws java.io.IOException
cmd
- the command line to sendjava.io.IOException
protected FTPResponse getResponse() throws java.io.IOException
java.io.IOException
protected FTPResponse readResponse() throws java.io.IOException
java.io.IOException