Package com.enterprisedt.net.ftp
Interface FTPClientInterface
- All Known Subinterfaces:
ProFTPClientInterface
- All Known Implementing Classes:
FTPClient,ProFTPClient,SSHFTPClient,SSLFTPClient
public interface FTPClientInterface
Defines operations in common with a number of FTP implementations.
- Version:
- $Revision$
- Author:
- Hans Andersen
-
Method Summary
Modifier and TypeMethodDescriptionvoidCancel the resume.voidCancels the current transfer.voidcdup()Change the remote working directory to the parent directoryvoidChange the remote working directory to that suppliedvoidconnect()Connects to the server at the address and port number defined in the constructor.booleanIs the client currently connected?voidDelete the specified remote fileString[]dir()List current directory's contents as an array of strings of filenames.String[]List a directory's contents as an array of strings of filenames.String[]List a directory's contents as an array of strings.FTPFile[]dirDetails(String dirname) List a directory's contents as an array of FTPFile objects.voiddirDetails(String dirname, DirectoryListCallback lister) List a directory's contents via a callback.executeCommand(String command) Request that the remote server execute the literal command supplied.booleanDoes the named file exist in the current server directory?voidget(OutputStream destStream, String remoteFile) Get data from the FTP server.byte[]Get data from the FTP server.voidGet data from the FTP server.intGet the number of files deleted since the count was resetbooleanGet the detect transfer modeintGet the number of files downloaded since the count was resetbooleanDetermine if file locking on local downloaded files is being used or not.getId()Get the identifying string for this instancelongGet the bytes transferred between each callback on the progress monitorintGet the size of the network buffers (SO_SNDBUF and SO_RCVBUF).Returns the IP address or name of the remote host.intReturns the port being connected to on the remote server.intGet the timeout used for sockets and other resourcesgetType()Get the current transfer typeintGet the number of files uploaded since the count was resetvoidTries to keep the current connection alive by some means, usually by sending an innocuous commmand.voidCreate the specified remote working directoryGet modification time for a remote file.Put data onto the FTP server.Put data onto the FTP server.put(InputStream srcStream, String remoteFile) Put a stream of data onto the FTP server.put(InputStream srcStream, String remoteFile, boolean append) Put a stream of data onto the FTP server.Put a local file onto the FTP server.Put a local file onto the FTP server.pwd()Get the current remote working directoryvoidquit()Quit the FTP sessionvoidQuit the FTP session immediately.voidRename a file or directoryvoidReset the count of deleted files to zero.voidReset the count of downloaded files to zero.voidReset the count of uploaded files to zero.voidresume()Make the next file transfer (put or get) resume.voidresumeNextDownload(long offset) Make the next download resume at a specific point.voidDelete the specified remote working directoryvoidsetControlEncoding(String controlEncoding) Set the encoding used on the control channel.voidsetDetectTransferMode(boolean detectTransferMode) Set autodetect of filetypes on or off.voidsetFileLockingEnabled(boolean lockingEnabled) Set file locking to enabled or disabled.voidSet the identifying string for this instancevoidsetModTime(String path, Date modTime) Set the last modified time (UTC) for the supplied file.voidsetNetworkBufferSize(int networkBufferSize) Set the size of the network buffers (SO_SNDBUF and SO_RCVBUF).voidsetProgressMonitor(FTPProgressMonitor monitor) Set a progress monitor for callbacks.voidsetProgressMonitor(FTPProgressMonitor monitor, long interval) Set a progress monitor for callbacks.voidsetRemoteHost(String remoteHost) Set the IP address or name of the remote host This may only be done if the client is not already connected to the server.voidsetRemotePort(int remotePort) Set the port to connect to on the remote server.voidsetTimeout(int millis) Set the timeout on the underlying sockets and other resources that may be used.voidsetType(FTPTransferType type) Set the transfer typelongGet the size of a remote file.system()Get a string representing the remote system
-
Method Details
-
getId
String getId()Get the identifying string for this instance- Returns:
- identifying string
-
setId
Set the identifying string for this instance- Parameters:
id- identifying string
-
getRemoteHost
String getRemoteHost()Returns the IP address or name of the remote host.- Returns:
- Returns the remote host.
-
setRemoteHost
Set the IP address or name of the remote host This may only be done if the client is not already connected to the server.- Parameters:
remoteHost- The IP address or name of the remote host- Throws:
FTPException- Thrown if the client is already connected to the server.IOException
-
getRemotePort
int getRemotePort()Returns the port being connected to on the remote server.- Returns:
- Returns the port being connected to on the remote server.
-
setRemotePort
Set the port to connect to on the remote server. Can only do this if not already connected.- Parameters:
remotePort- The port to use.- Throws:
FTPException- Thrown if the client is already connected to the server.
-
getTimeout
int getTimeout()Get the timeout used for sockets and other resources- Returns:
- timeout that is used, in milliseconds
-
setTimeout
Set the timeout on the underlying sockets and other resources that may be used. A timeout of 0 should not be used - for an infinite timeout use a large number. Timeouts should be set before connections are made. If a timeout is set, then any operation which takes longer than the timeout value will be result in an IOException being thrown. The default is 60,000 (60 seconds).- Parameters:
millis- The length of the timeout, in milliseconds- Throws:
IOExceptionFTPException
-
getNetworkBufferSize
int getNetworkBufferSize()Get the size of the network buffers (SO_SNDBUF and SO_RCVBUF).- Returns:
- network buffer size
-
setNetworkBufferSize
void setNetworkBufferSize(int networkBufferSize) Set the size of the network buffers (SO_SNDBUF and SO_RCVBUF).- Parameters:
networkBufferSize- new buffer size to set
-
setProgressMonitor
Set a progress monitor for callbacks. The bytes transferred in between callbacks is only indicative. In many cases, the data is read in chunks, and if the interval is set to be smaller than the chunk size, the callback will occur after after chunk transfer rather than the interval. Depending on the implementation, the chunk size can be as large as 64K.- Parameters:
monitor- the monitor objectinterval- bytes transferred in between callbacks
-
setProgressMonitor
Set a progress monitor for callbacks. Uses default callback interval- Parameters:
monitor- the monitor object
-
getMonitorInterval
long getMonitorInterval()Get the bytes transferred between each callback on the progress monitor- Returns:
- long bytes to be transferred before a callback
-
setDetectTransferMode
void setDetectTransferMode(boolean detectTransferMode) Set autodetect of filetypes on or off. If on, the transfer mode is switched from ASCII to binary and vice versa depending on the extension of the file. After the transfer, the mode is always returned to what it was before the transfer was performed. The default is off. If the filetype is unknown, the transfer mode is unchanged- Parameters:
detectTransferMode- true if detecting transfer mode, false if not
-
getDetectTransferMode
boolean getDetectTransferMode()Get the detect transfer mode- Returns:
- true if we are detecting binary and ASCII transfers from the file type
-
setFileLockingEnabled
void setFileLockingEnabled(boolean lockingEnabled) Set file locking to enabled or disabled. When downloading files, by default the local file is locked for exclusive writing to prevent other processes corrupting it. Sometimes this needs to be disabled, e.g. tryLock() fails on NFS drives in versions of Java prior to 7.- Parameters:
lockingEnabled- true to enable locking, false to disable
-
getFileLockingEnabled
boolean getFileLockingEnabled()Determine if file locking on local downloaded files is being used or not. Default is true.- Returns:
- true if file locking is enabled, false otherwise
-
setControlEncoding
Set the encoding used on the control channel. Can only do this if not connected- Parameters:
controlEncoding- The controlEncoding to set, which is the name of a Charset- Throws:
FTPException- See Also:
-
connect
Connects to the server at the address and port number defined in the constructor.- Throws:
IOException- Thrown if there is a TCP/IP-related error.FTPException- Thrown if there is an error related to the FTP protocol.
-
connected
boolean connected()Is the client currently connected?- Returns:
- true if connected, false otherwise
-
size
Get the size of a remote file. This is not a standard FTP command, it is defined in "Extensions to FTP", a draft RFC (draft-ietf-ftpext-mlst-16.txt)- Parameters:
remoteFile- name or path of remote file in current directory- Returns:
- size of file in bytes
- Throws:
IOExceptionFTPException
-
exists
Does the named file exist in the current server directory?- Parameters:
remoteFile- name of remote file- Returns:
- true if exists, false otherwise
- Throws:
IOExceptionFTPException
-
executeCommand
Request that the remote server execute the literal command supplied. In FTP and SFTP, this might be a SITE command, while in SFTP it might be a shell command.It is up to the user to send a sensible command.
- Parameters:
command- command string- Returns:
- result string by server
- Throws:
FTPExceptionIOException
-
system
Get a string representing the remote system- Returns:
- system string
- Throws:
FTPExceptionIOException
-
getType
FTPTransferType getType()Get the current transfer type- Returns:
- the current type of the transfer, i.e. BINARY or ASCII
-
setType
Set the transfer type- Parameters:
type- the transfer type to set the server to- Throws:
IOExceptionFTPException
-
resume
Make the next file transfer (put or get) resume. For puts(), the bytes already transferred are skipped over, while for gets(), if writing to a file, it is opened in append mode, and only the bytes required are transferred. Currently resume is only supported for BINARY transfers (which is generally what it is most useful for).- Throws:
FTPException
-
resumeNextDownload
Make the next download resume at a specific point. This resume method allows the resume offset to be set explicitly for downloads. Offset bytes are skipped before downloading the file. This means you can download only the last few bytes of the file rather than the whole file, irrespective of the size of the local file. Currently resume is only supported for BINARY transfers (which is generally what it is most useful for).- Throws:
FTPException
-
cancelResume
Cancel the resume. Use this method if something goes wrong and the server is left in an inconsistent state- Throws:
IOExceptionFTPException
-
cancelTransfer
void cancelTransfer()Cancels the current transfer. Generally called from a separate thread. Note that this may leave partially written files on the server or on local disk, and should not be used unless absolutely necessary. After the transfer is cancelled the connection may be in an inconsistent state, therefore it is best to quit and reconnect. It may cause exceptions to be thrown depending on the underlying protocol being used. Note that this can also be used to cancel directory listings, which can involve large amounts of data for directories containing many files. -
put
Put a local file onto the FTP server. It is placed in the current directory. If a remote file name is supplied, it is stored as that name on the server. If null is supplied, the server will generate a unique filename (via STOU) if it supports this option.- Parameters:
localPath- path of the local fileremoteFile- name of remote file in current directory, or null if a unique filename is to be generated by the server- Returns:
- The name of the remote file - normally the name supplied, or else the unique name generated by the server.
- Throws:
IOExceptionFTPException
-
put
Put a stream of data onto the FTP server. It is placed in the current directory. If a remote file name is supplied, it is stored as that name on the server. If null is supplied, the server will generate a unique filename (via STOU) if it supports this option.- Parameters:
srcStream- input stream of data to putremoteFile- name of remote file in current directory, or null if a unique filename is to be generated by the server- Returns:
- The name of the remote file - normally the name supplied, or else the unique name generated by the server.
- Throws:
IOExceptionFTPException
-
put
String put(InputStream srcStream, String remoteFile, boolean append) throws IOException, FTPException Put a stream of data onto the FTP server. It is placed in the current directory. If a remote file name is supplied, it is stored as that name on the server. If null is supplied, the server will generate a unique filename (via STOU) if it supports this option. Allows appending if current file exists.- Parameters:
srcStream- input stream of data to putremoteFile- name of remote file in current directory, or null if a unique filename is to be generated by the serverappend- true if appending, false otherwise- Returns:
- The name of the remote file - normally the name supplied, or else the unique name generated by the server.
- Throws:
IOExceptionFTPException
-
put
Put data onto the FTP server. It is placed in the current directory. If a remote file name is supplied, it is stored as that name on the server. If null is supplied, the server will generate a unique filename (via STOU) if it supports this option.- Parameters:
bytes- array of bytesremoteFile- name of remote file in current directory, or null if a unique filename is to be generated by the server- Returns:
- The name of the remote file - normally the name supplied, or else the unique name generated by the server.
- Throws:
IOExceptionFTPException
-
put
Put data onto the FTP server. It is placed in the current directory. If a remote file name is supplied, it is stored as that name on the server. If null is supplied, the server will generate a unique filename (via STOU) if it supports this option. Allows appending if current file exists.- Parameters:
bytes- array of bytesremoteFile- name of remote file in current directory, or null if a unique filename is to be generated by the serverappend- true if appending, false otherwise- Returns:
- The name of the remote file - normally the name supplied, or else the unique name generated by the server.
- Throws:
IOExceptionFTPException
-
put
Put a local file onto the FTP server. It is placed in the current directory. If a remote file name is supplied, it is stored as that name on the server. If null is supplied, the server will generate a unique filename (via STOU) if it supports this option. Allows appending if current file exists.- Parameters:
localPath- path of the local fileremoteFile- name of remote file in current directory, or null if a unique filename is to be generated by the serverappend- true if appending, false otherwise- Returns:
- The name of the remote file - normally the name supplied, or else the unique name generated by the server.
- Throws:
IOExceptionFTPException
-
get
Get data from the FTP server. Uses the currently set transfer mode.- Parameters:
localPath- local file to put data inremoteFile- name of remote file in current directory- Throws:
IOExceptionFTPException
-
get
Get data from the FTP server. Uses the currently set transfer mode.- Parameters:
destStream- data stream to write data toremoteFile- name of remote file in current directory- Throws:
IOExceptionFTPException
-
get
Get data from the FTP server. Transfers in whatever mode we are in. Retrieve as a byte array. Note that we may experience memory limitations as the entire file must be held in memory at one time.- Parameters:
remoteFile- name of remote file in current directory- Throws:
IOExceptionFTPException
-
getDownloadCount
int getDownloadCount()Get the number of files downloaded since the count was reset- Returns:
- download file count
-
resetDownloadCount
void resetDownloadCount()Reset the count of downloaded files to zero. -
getUploadCount
int getUploadCount()Get the number of files uploaded since the count was reset- Returns:
- upload file count
-
resetUploadCount
void resetUploadCount()Reset the count of uploaded files to zero. -
getDeleteCount
int getDeleteCount()Get the number of files deleted since the count was reset- Returns:
- deleted file count
-
resetDeleteCount
void resetDeleteCount()Reset the count of deleted files to zero. -
dirDetails
void dirDetails(String dirname, DirectoryListCallback lister) throws IOException, FTPException, ParseException List a directory's contents via a callback. The callback is notified for each directory entry, meaning they can be processed individually. It also avoids out of memory problems if the directory is huge, and an array of thousands of FTPFile objects would otherwise be returned. Most servers return an empty directory listing if a directory does not exist, and this is also what this method does. To establish whether or not a directory exists, try changing into it.- Parameters:
dirname- name of directory (some servers permit a filemask)lister- callback to be notified of errors- Throws:
IOExceptionFTPExceptionParseException
-
dirDetails
List a directory's contents as an array of FTPFile objects. Most servers return an empty directory listing if a directory does not exist, and this is also what this method does. To establish whether or not a directory exists, try changing into it. Should work for Windows and most Unix FTP servers - let us know about unusual formats (http://www.enterprisedt.com/forums/index.php). If accurate timestamps are required (i.e. to the second), it is generally better to use @see #modtime(String).- Parameters:
dirname- name of directory (some servers permit a filemask)- Returns:
- an array of FTPFile objects
- Throws:
IOExceptionFTPExceptionParseException
-
dir
List current directory's contents as an array of strings of filenames. Most servers return an empty directory listing if a directory does not exist, and this is also what this method does. To establish whether or not a directory exists, try changing into it.- Returns:
- an array of current directory listing strings
- Throws:
IOExceptionFTPException
-
dir
List a directory's contents as an array of strings of filenames. Most servers return an empty directory listing if a directory does not exist, and this is also what this method does. To establish whether or not a directory exists, try changing into it.- Parameters:
dirname- name of directory OR filemask- Returns:
- an array of directory listing strings
- Throws:
IOExceptionFTPException
-
dir
List a directory's contents as an array of strings. A detailed listing is available, otherwise just filenames are provided. The detailed listing varies in details depending on OS and FTP server. Note that a full listing can be used on a file name to obtain information about a file. Most servers return an empty directory listing if a directory does not exist, and this is also what this method does. To establish whether or not a directory exists, try changing into it.- Parameters:
dirname- name of directory OR filemaskfull- true if detailed listing required false otherwise- Returns:
- an array of directory listing strings
- Throws:
IOExceptionFTPException
-
delete
Delete the specified remote file- Parameters:
remoteFile- name of remote file to delete- Throws:
IOExceptionFTPException
-
rename
Rename a file or directory- Parameters:
from- name of file or directory to renameto- intended name- Throws:
IOExceptionFTPException
-
rmdir
Delete the specified remote working directory- Parameters:
dir- name of remote directory to delete- Throws:
IOExceptionFTPException
-
mkdir
Create the specified remote working directory- Parameters:
dir- name of remote directory to create- Throws:
IOExceptionFTPException
-
chdir
Change the remote working directory to that supplied- Parameters:
dir- name of remote directory to change to- Throws:
IOExceptionFTPException
-
cdup
Change the remote working directory to the parent directory- Throws:
IOExceptionFTPException
-
modtime
Get modification time for a remote file. For accurate modification times (e.g. to the second) this method is to be preferred over @see #dirDetails(java.lang.String) which parses a listing returned by the server. The time zone is UTC.- Parameters:
remoteFile- name of remote file- Throws:
IOExceptionFTPException
-
setModTime
Set the last modified time (UTC) for the supplied file. This is not supported by all servers.- Parameters:
path- the path to the file/directory on the remote servermodTime- the time stamp to set the modified time to in UTC- Throws:
IOExceptionFTPException
-
pwd
Get the current remote working directory- Returns:
- the current working directory
- Throws:
IOExceptionFTPException
-
keepAlive
Tries to keep the current connection alive by some means, usually by sending an innocuous commmand.- Throws:
IOExceptionFTPException
-
quit
Quit the FTP session- Throws:
IOExceptionFTPException
-
quitImmediately
Quit the FTP session immediately. If a transfer is underway it will be terminated.- Throws:
IOExceptionFTPException
-