public class FTPConnection extends Object
| Modifier and Type | Field and Description |
|---|---|
protected static String |
ABOR |
protected static String |
ACCT |
protected static String |
ALLO |
protected static String |
APPE |
protected static String |
AUTH |
protected static String |
CCC |
protected static String |
CDUP |
protected int |
connectionTimeout
The timeout when attempting to connect a socket.
|
protected static String |
CWD |
protected boolean |
debug
If true, print debugging information.
|
protected static 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 String |
HELP |
protected LineInputStream |
in
The socket input stream.
|
protected static String |
LIST |
protected static String |
MKD |
protected static String |
MODE |
static int |
MODE_BLOCK |
static int |
MODE_COMPRESSED |
static int |
MODE_STREAM |
protected static String |
NLST |
protected static String |
NOOP |
protected CRLFOutputStream |
out
The socket output stream.
|
protected static String |
PASS |
protected boolean |
passive
If true, use passive mode.
|
protected static String |
PASV |
protected static String |
PBSZ |
protected static String |
PORT |
protected static String |
PROT |
protected static String |
PWD |
protected static String |
QUIT |
protected static String |
REIN |
protected int |
representationType
The current representation type.
|
protected static String |
REST |
protected static String |
RETR |
protected static String |
RMD |
protected static String |
RNFR |
protected static String |
RNTO |
protected static String |
SITE |
protected static String |
SMNT |
protected Socket |
socket
The socket used to communicate with the server.
|
protected static String |
STAT |
protected static String |
STOR |
protected static String |
STOU |
protected static String |
STRU |
static int |
STRUCTURE_FILE |
static int |
STRUCTURE_PAGE |
static int |
STRUCTURE_RECORD |
protected static String |
SYST |
protected int |
timeout
The read timeout on sockets.
|
protected static String |
TLS |
protected int |
transferMode
The current transfer mode.
|
protected static String |
TYPE |
static int |
TYPE_ASCII |
static int |
TYPE_BINARY |
static int |
TYPE_EBCDIC |
protected static String |
USER |
| Constructor and Description |
|---|
FTPConnection(String hostname)
Creates a new connection to the server using the default port.
|
FTPConnection(String hostname,
int port)
Creates a new connection to the server.
|
FTPConnection(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.
|
OutputStream |
append(String filename)
Returns a stream for uploading a file.
|
boolean |
authenticate(String username,
String password)
Authenticate using the specified username and password.
|
boolean |
changeToParentDirectory()
Changes directory to the parent of the current working directory.
|
boolean |
changeWorkingDirectory(String path)
Changes directory to the specified path.
|
boolean |
delete(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.
|
String |
getWorkingDirectory()
Returns the current working directory.
|
protected void |
initialiseDTP()
Initialise the data transfer process.
|
InputStream |
list(String pathname)
Returns a listing of information about the specified pathname.
|
void |
logout()
Terminates the control connection.
|
boolean |
makeDirectory(String pathname)
Causes the directory specified to be created at the server site.
|
List |
nameList(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(String pathname)
Causes the directory specified to be deleted.
|
boolean |
rename(String oldName,
String newName)
Renames a file.
|
InputStream |
retrieve(String filename)
Retrieves the specified file.
|
protected void |
send(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,
TrustManager tm)
Negotiates TLS over the current connection.
|
OutputStream |
store(String filename)
Returns a stream for uploading a file.
|
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 String USER
protected static final String PASS
protected static final String ACCT
protected static final String CWD
protected static final String CDUP
protected static final String SMNT
protected static final String REIN
protected static final String QUIT
protected static final String PORT
protected static final String PASV
protected static final String TYPE
protected static final String STRU
protected static final String MODE
protected static final String RETR
protected static final String STOR
protected static final String STOU
protected static final String APPE
protected static final String ALLO
protected static final String REST
protected static final String RNFR
protected static final String RNTO
protected static final String ABOR
protected static final String DELE
protected static final String RMD
protected static final String MKD
protected static final String PWD
protected static final String LIST
protected static final String NLST
protected static final String SITE
protected static final String SYST
protected static final String STAT
protected static final String HELP
protected static final String NOOP
protected static final String AUTH
protected static final String PBSZ
protected static final String PROT
protected static final String CCC
protected static final 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 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(String hostname) throws UnknownHostException, IOException
hostname - the hostname of the server to connect toUnknownHostExceptionIOExceptionpublic FTPConnection(String hostname, int port) throws UnknownHostException, IOException
hostname - the hostname of the server to connect toport - the port to connect to(if <=0, use default port)UnknownHostExceptionIOExceptionpublic FTPConnection(String hostname, int port, int connectionTimeout, int timeout, boolean debug) throws UnknownHostException, 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 informationUnknownHostExceptionIOExceptionpublic boolean authenticate(String username, String password) throws IOException
username - the usernamepassword - the optional passwordIOExceptionpublic boolean starttls(boolean confidential)
throws IOException
confidential - whether to provide confidentiality for the
connectionIOExceptionpublic boolean starttls(boolean confidential,
TrustManager tm)
throws IOException
confidential - whether to provide confidentiality for the
connectiontm - the trust manager used to validate the server certificate.IOExceptionpublic boolean changeWorkingDirectory(String path) throws IOException
path - an absolute or relative pathnameIOExceptionpublic boolean changeToParentDirectory()
throws IOException
IOExceptionpublic void reinitialize()
throws IOException
IOExceptionpublic void logout()
throws IOException
IOExceptionprotected void initialiseDTP()
throws IOException
IOExceptionpublic void setPassive(boolean flag)
throws IOException
flag - true if we should use passive mode, false otherwiseIOExceptionpublic int getRepresentationType()
public void setRepresentationType(int type)
throws IOException
type - TYPE_ASCII, TYPE_EBCDIC, or TYPE_BINARYIOExceptionpublic int getFileStructure()
public void setFileStructure(int structure)
throws IOException
structure - STRUCTURE_FILE, STRUCTURE_RECORD, or STRUCTURE_PAGEIOExceptionpublic int getTransferMode()
public void setTransferMode(int mode)
throws IOException
mode - MODE_STREAM, MODE_BLOCK, or MODE_COMPRESSEDIOExceptionpublic InputStream retrieve(String filename) throws IOException
filename - the filename of the file to retrieveIOExceptionpublic OutputStream store(String filename) throws IOException
filename - the name of the file to save the content asIOExceptionpublic OutputStream append(String filename) throws IOException
filename - the name of the file to save the content asIOExceptionpublic void allocate(long size)
throws IOException
store or
append.size - the number of bytes of storage to allocateIOExceptionpublic boolean rename(String oldName, String newName) throws IOException
oldName - the current name of the filenewName - the new nameIOExceptionpublic boolean abort()
throws IOException
IOExceptionpublic boolean delete(String filename) throws IOException
filename - the file to deleteIOExceptionpublic boolean removeDirectory(String pathname) throws IOException
pathname - the directory to deleteIOExceptionpublic boolean makeDirectory(String pathname) throws IOException
pathname - the directory to createIOExceptionpublic String getWorkingDirectory() throws IOException
IOExceptionpublic InputStream list(String pathname) throws IOException
pathname - the context pathname, or nullIOExceptionpublic List nameList(String pathname) throws IOException
pathname - the directory pathname, or nullIOExceptionpublic String system() throws IOException
IOExceptionpublic void noop()
throws IOException
IOExceptionprotected void send(String cmd) throws IOException
cmd - the command line to sendIOExceptionprotected FTPResponse getResponse() throws IOException
IOExceptionprotected FTPResponse readResponse() throws IOException
IOExceptionCopyright © 2017. All rights reserved.