ABOR
protected static final java.lang.String ABOR
- "ABOR"
ACCT
protected static final java.lang.String ACCT
- "ACCT"
ALLO
protected static final java.lang.String ALLO
- "ALLO"
APPE
protected static final java.lang.String APPE
- "APPE"
CDUP
protected static final java.lang.String CDUP
- "CDUP"
CWD
protected static final java.lang.String CWD
- "CWD"
DELE
protected static final java.lang.String DELE
- "DELE"
FTP_DATA_PORT
public static final int FTP_DATA_PORT
The FTP data port.
- 20
FTP_PORT
public static final int FTP_PORT
The default FTP transmission control port.
- 21
HELP
protected static final java.lang.String HELP
- "HELP"
LIST
protected static final java.lang.String LIST
- "LIST"
MKD
protected static final java.lang.String MKD
- "MKD"
MODE
protected static final java.lang.String MODE
- "MODE"
MODE_BLOCK
public static final int MODE_BLOCK
- 2
MODE_COMPRESSED
public static final int MODE_COMPRESSED
- 3
MODE_STREAM
public static final int MODE_STREAM
- 1
NLST
protected static final java.lang.String NLST
- "NLST"
NOOP
protected static final java.lang.String NOOP
- "NOOP"
PASS
protected static final java.lang.String PASS
- "PASS"
PASV
protected static final java.lang.String PASV
- "PASV"
PORT
protected static final java.lang.String PORT
- "PORT"
PWD
protected static final java.lang.String PWD
- "PWD"
QUIT
protected static final java.lang.String QUIT
- "QUIT"
REIN
protected static final java.lang.String REIN
- "REIN"
REST
protected static final java.lang.String REST
- "REST"
RETR
protected static final java.lang.String RETR
- "RETR"
RMD
protected static final java.lang.String RMD
- "RMD"
RNFR
protected static final java.lang.String RNFR
- "RNFR"
RNTO
protected static final java.lang.String RNTO
- "RNTO"
SITE
protected static final java.lang.String SITE
- "SITE"
SMNT
protected static final java.lang.String SMNT
- "SMNT"
STAT
protected static final java.lang.String STAT
- "STAT"
STOR
protected static final java.lang.String STOR
- "STOR"
STOU
protected static final java.lang.String STOU
- "STOU"
STRU
protected static final java.lang.String STRU
- "STRU"
STRUCTURE_FILE
public static final int STRUCTURE_FILE
- 1
STRUCTURE_PAGE
public static final int STRUCTURE_PAGE
- 3
STRUCTURE_RECORD
public static final int STRUCTURE_RECORD
- 2
SYST
protected static final java.lang.String SYST
- "SYST"
TYPE
protected static final java.lang.String TYPE
- "TYPE"
TYPE_ASCII
public static final int TYPE_ASCII
- 1
TYPE_BINARY
public static final int TYPE_BINARY
- 3
TYPE_EBCDIC
public static final int TYPE_EBCDIC
- 2
USER
protected static final java.lang.String USER
- "USER"
connectionTimeout
protected int connectionTimeout
The timeout when attempting to connect a socket.
debug
protected boolean debug
If true, print debugging information.
dtp
protected gnu.inet.ftp.DTP dtp
The current data transfer process in use by this connection.
fileStructure
protected int fileStructure
The current file structure type.
out
protected java.io.OutputStream out
The socket output stream.
passive
protected boolean passive
If true, use passive mode.
representationType
protected int representationType
The current representation type.
socket
protected java.net.Socket socket
The socket used to communicate with the server.
timeout
protected int timeout
The read timeout on sockets.
transferMode
protected int transferMode
The current transfer mode.
FTPConnection
public FTPConnection(java.lang.String hostname)
throws java.net.UnknownHostException,
java.io.IOException
Creates a new connection to the server using the default port.
hostname
- the hostname of the server to connect to
FTPConnection
public FTPConnection(java.lang.String hostname,
int port)
throws java.net.UnknownHostException,
java.io.IOException
Creates a new connection to the server.
hostname
- the hostname of the server to connect toport
- the port to connect to (if <=0, use default port)
FTPConnection
public FTPConnection(java.lang.String hostname,
int port,
int connectionTimeout,
int timeout,
boolean debug)
throws java.net.UnknownHostException,
java.io.IOException
Creates a new connection to the server.
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 information
abort
public boolean abort()
throws java.io.IOException
Aborts the transfer in progress.
- true if a transfer was in progress, false otherwise
allocate
public void allocate(long size)
throws java.io.IOException
This command may be required by some servers to reserve sufficient
storage to accommodate the new file to be transferred.
It should be immediately followed by a store
or
append
.
size
- the number of bytes of storage to allocate
append
public java.io.OutputStream append(java.lang.String filename)
throws java.io.IOException
Returns a stream for uploading a file.
If a file with the same filename already exists on the server, the
content specified will be appended to the existing file.
filename
- the name of the file to save the content as
- an OutputStream to write the file data to
authenticate
public boolean authenticate(java.lang.String username,
java.lang.String password)
throws java.io.IOException
Authenticate using the specified username and password.
If the username suffices for the server, the password will not be used
and may be null.
username
- the usernamepassword
- the optional password
- true on success, false otherwise
changeToParentDirectory
public boolean changeToParentDirectory()
throws java.io.IOException
Changes directory to the parent of the current working directory.
- true on success, false otherwise
changeWorkingDirectory
public boolean changeWorkingDirectory(java.lang.String path)
throws java.io.IOException
Changes directory to the specified path.
path
- an absolute or relative pathname
- true on success, false if the specified path does not exist
delete
public boolean delete(java.lang.String filename)
throws java.io.IOException
Causes the file specified to be deleted at the server site.
filename
- the file to delete
getFileStructure
public int getFileStructure()
Returns the current file structure type.
- STRUCTURE_FILE, STRUCTURE_RECORD, or STRUCTURE_PAGE
getRepresentationType
public int getRepresentationType()
Returns the current representation type of the transfer data.
- TYPE_ASCII, TYPE_EBCDIC, or TYPE_BINARY
getResponse
protected FTPResponse getResponse()
throws java.io.IOException
Reads the next response from the server.
If the server sends the "transfer complete" code, this is handled here,
and the next response is passed to the caller.
getTransferMode
public int getTransferMode()
Returns the current transfer mode.
- MODE_STREAM, MODE_BLOCK, or MODE_COMPRESSED
getWorkingDirectory
public java.lang.String getWorkingDirectory()
throws java.io.IOException
Returns the current working directory.
initialiseDTP
protected void initialiseDTP()
throws java.io.IOException
Initialise the data transfer process.
list
public java.io.InputStream list(java.lang.String pathname)
throws java.io.IOException
Returns a listing of information about the specified pathname.
If the pathname specifies a directory or other group of files, the
server should transfer a list of files in the specified directory.
If the pathname specifies a file then the server should send current
information on the file. A null argument implies the user's
current working or default directory.
pathname
- the context pathname, or null
logout
public void logout()
throws java.io.IOException
Terminates the control connection.
The file transfer connection remains open for result response only.
This connection is invalid and no further commands may be issued.
makeDirectory
public boolean makeDirectory(java.lang.String pathname)
throws java.io.IOException
Causes the directory specified to be created at the server site.
This may be an absolute or relative pathname.
pathname
- the directory to create
nameList
public java.util.List nameList(java.lang.String pathname)
throws java.io.IOException
Returns a directory listing. The pathname should specify a
directory or other system-specific file group descriptor; a null
argument implies the user's current working or default directory.
pathname
- the directory pathname, or null
- a list of filenames (strings)
noop
public void noop()
throws java.io.IOException
Does nothing.
This method can be used to ensure that the connection does not time
out.
readResponse
protected FTPResponse readResponse()
throws java.io.IOException
Reads and parses the next response from the server.
reinitialize
public void reinitialize()
throws java.io.IOException
Terminates an authenticated login.
If file transfer is in progress, it remains active for result response
only.
removeDirectory
public boolean removeDirectory(java.lang.String pathname)
throws java.io.IOException
Causes the directory specified to be deleted.
This may be an absolute or relative pathname.
pathname
- the directory to delete
rename
public boolean rename(java.lang.String oldName,
java.lang.String newName)
throws java.io.IOException
Renames a file.
oldName
- the current name of the filenewName
- the new name
- true if successful, false otherwise
retrieve
public java.io.InputStream retrieve(java.lang.String filename)
throws java.io.IOException
Retrieves the specified file.
filename
- the filename of the file to retrieve
- an InputStream containing the file content
send
protected void send(java.lang.String cmd)
throws java.io.IOException
Sends the specified command line to the server.
The CRLF sequence is automatically appended.
cmd
- the command line to send
setFileStructure
public void setFileStructure(int structure)
throws java.io.IOException
Sets the desired file structure type.
structure
- STRUCTURE_FILE, STRUCTURE_RECORD, or STRUCTURE_PAGE
setPassive
public void setPassive(boolean flag)
throws java.io.IOException
Set passive mode.
flag
- true if we should use passive mode, false otherwise
setRepresentationType
public void setRepresentationType(int type)
throws java.io.IOException
Sets the desired representation type of the transfer data.
type
- TYPE_ASCII, TYPE_EBCDIC, or TYPE_BINARY
setTransferMode
public void setTransferMode(int mode)
throws java.io.IOException
Sets the desired transfer mode.
mode
- MODE_STREAM, MODE_BLOCK, or MODE_COMPRESSED
store
public java.io.OutputStream store(java.lang.String filename)
throws java.io.IOException
Returns a stream for uploading a file.
If a file with the same filename already exists on the server, it will
be overwritten.
filename
- the name of the file to save the content as
- an OutputStream to write the file data to
system
public java.lang.String system()
throws java.io.IOException
Returns the type of operating system at the server.