Class SSHFTPClient
- All Implemented Interfaces:
FTPClientInterface,ProFTPClientInterface
SSHFTPClient implements SFTP (SSH File Transfer Protocol).
Connections are established when the connect() is invoked.
Before it is called, the remote host must be defined, and
host verification and client authentication should be
configured.
Host Validation is the process of verifying that a host that is
being connected to is the host that was requested. Host validation is
done through an instance of SSHFTPValidator or a subclass
thereof. By default, SSHFTPClient, has an instance of
this class that is available by means of the getValidator()
method. Unless specialized validation functionality is required,
initialization of validation functionality may be done simply by invoking
methods on this object.
There are four approaches to setting up host validation:
- Disabling host validation. In
general this represents a security weakness and should therefore be used
only when testing code. This mode is selected as follows:
ftpClient.getValidator().setHostValidationEnabled(false);
- Initialize from a hosts file: A list of known hosts and their
public keys are loaded from a file. The format of the file is similar to
that used in OpenSSH. Each line contains the name of a host, the type of
key it has, and its key (in base-64 printable form). For example:
jackspc ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAIE...
If there are more than one host using a given key the host-name may be replaced by a comma-separated list of host-names. Wildcards may not be used. A host-file is loaded as follows:ftpClient.getValidator().loadKnownHosts("~/.ssh/known_hosts"); - Initialize programmatically: Host public keys may be loaded
from individual files as follows:
ftpClient.getValidator().addKnownHost("host1pk.pub"); ftpClient.getValidator().addKnownHost("host2pk.pub");Public keys should be in OpenSSH or SECSH format.
Client Authentication is the method used by the server to authenticate
clients. Different servers will enforce different policies for authenticating
clients. SSHFTPClient currently offers two authentication methods:
- User-name/Password Authentication involves simply passing a
user-name/password to the server for authentication. This is set up simply by
by calling
setAuthenticationas follows:ftpClient.setAuthentication("jack", "my_ftp_password"); - Public Key Authentication involves using a private/public key pair
to authenticate the client. The key pair must be in a file in OpenSSH or SECSH format
and the name is passed as follows:
ftpClient.setAuthentication("myprivatekey", "jack", "my_keyfile_password");The user-name is the name of the user on the SFTP server, but the passphrase is the password for the key-file (if there is a password).
- Version:
- $Revision$
- Author:
- Hans Andersen
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classConfigFlagscontains various static integers which are used to configure clients. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringDefault encoding used for control datastatic final StringCarriage return + line feed end of line markerstatic final StringLine feed end of line markerFields inherited from class com.enterprisedt.net.ftp.ssh.SCPClient
authenticator, connProps, DEFAULT_PORT, deleteCount, downloadCount, id, license, proxySettings, retryAuthenticator, ssh, uploadCount, validatorFields inherited from interface com.enterprisedt.net.ftp.pro.ProFTPClientInterface
cvsId -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidCancel the resume.voidCancels the current transfer.voidcdup()Change the remote working directory to the parent directoryvoidchangeGroup(int gid, String path) Sets the group ID for the file or directory.voidchangeMode(int permissions, String path) Changes the access permissions or modes of the specified file or directory.voidchangeMode(String permissions, String path) Changes the access permissions or modes of the specified file or directory.voidchangeOwner(int uid, String path) Sets the user ID to owner for the file or directory.voidChange the remote working directory to that suppliedbooleanCheck that a directory is readable prior to changing into itvoidconnect()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.booleanDoes the named file exist in the current server directory?fileDetails(String name) Get details about the named filevoidget(OutputStream destStream, String remoteFile) Get data from the FTP server.byte[]Get data from the FTP server.voidDownload a fileintGet the set configuration flags.intGet the number of transfers set before sleepingGet the EOL detected by the clientbooleanGet the detect transfer modebooleanDetermine if file locking on local downloaded files is being used or not.static SSHFTPPublicKeygetHostPublicKey(String remoteHost) Helper method that may be used to obtain a server's public key without instantiating anSSHFTPClient.static SSHFTPPublicKeygetHostPublicKey(String remoteHost, int remotePort) Helper method that may be used to obtain a server's public key without instantiating anSSHFTPClient.intGet the max packet size setintintGet the maximum bandwidth for transferslongGet the bytes transferred between each callback on the progress monitorGet the reference to the progress monitorGet reference to the transfer listenerGet the remote EOL string that is forced to be used irrespective of what is detected from server information.longDeprecated.Returns the server-side path of the SFTP subsystem (default is null).intGet the number of seconds spent asleepintGet the size of the buffers used in writing to and reading from the servergetType()Get the current transfer typegetUmask()Get the current umaskbooleanIs the client in parallel write mode, which is the defaultbooleanbooleanIs sleeping enabled?booleanHas the current transfer been cancelled?voidTries to keep the current connection alive by sending an innocuous command to signal that the client is still activevoidmdelete(FileFilter filter) Deletes all files matching the filter in the current remote directory onlyvoidDeletes all files matching the wildcard in the current remote directory onlyvoidmdelete(String remoteDir, FileFilter filter, boolean recurse) Delete all the files in this directory (and its subdirectories if recurse is true) that match the supplied filter.voidDelete all the files in this directory (and its subdirectories if recurse is true) that match the supplied wildcard.voidmget(String localDir, FileFilter filter) Get all files matching the filter in the current remote directory only into the supplied local directoryvoidGet all files matching the filter in the current remote directory only into the supplied local directoryvoidmget(String localDir, String remoteDir, FileFilter filter, boolean recurse) Gets this entire remote directory and its contents, recursively going through the remote directory name supplied.voidGets this entire remote directory and its contents, recursively going through the remote directory name supplied.voidCreate the specified remote working directoryGet modification time for a remote file.voidmput(String localDir, FileFilter filter) Put all files matching the wildcard in the supplied local directory only into the current remote directoryvoidPut all files matching the wildcard in the supplied local directory only into the current remote directoryvoidmput(String localDir, String remoteDir, FileFilter filter, boolean recurse) Puts this entire directory and its contents.voidPuts this entire directory and its contents.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.Upload a file.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 directoryvoidresume()Make the next file transfer (put or get) resume.voidresumeNextDownload(long offset) Resumes the next download from the offset point, which must be smaller than the length of the file to be downloaded.voidDelete the specified remote working directoryvoidDelete this remote directory.voidsetCheckDirReadableForChDir(boolean checkDirReadableForChDir) Set the check for directory readability prior to changing the directory on or offvoidsetConfigFlags(int configFlags) Set the configuration flags.voidsetControlEncoding(String controlEncoding) Set the encoding.voidsetCountBeforeSleep(int countBeforeSleep) Set the number of transfers required before sleepingvoidsetDetectTransferMode(boolean detectTransferMode) Set autodetect of filetypes on or off.voidsetFileLockingEnabled(boolean fileLockingEnabled) Set file locking to enabled or disabled.voidsetMaxPacketSize(int maxPacketSize) Set the maximum packet size.voidsetMaxQueuedReadRequests(int maxQueuedReadRequests) In SFTP, files are read block-by-block.voidsetMaxTransferRate(int thresholdBytesPerSecond) Set the maximum transfer rates in bytes per secvoidsetModTime(String path, Date modTime) Set the last modified time for the supplied filevoidsetMonitorInterval(long interval) Set the progress monitor interval for notificationsvoidsetParallelMode(boolean parallelWriteMode) Switch parallel write mode on or offvoidsetProgressMonitor(FTPProgressMonitor monitor) Set a progress monitor for callbacks.voidsetProgressMonitor(FTPProgressMonitor monitor, long interval) Set a progress monitor for callbacks.voidsetProgressMonitorEx(FTPProgressMonitorEx monitorEx) Set reference to the transfer listenervoidsetRemoteEOL(String remoteEOL) Set a remoteEOL to be forced, irrespective of what is detected from server information.voidsetSCPMode(boolean on) Set the SCP mode.voidsetServerResponseTimeout(long serverResponseTimeout) Deprecated.UsesetTimeout(int)voidsetSFTPSubsystemPath(String sftpSubsystemPath) Sets the server-side path of the SFTP subsystem (default is null).voidsetSleepEnabled(boolean sleepEnabled) Set sleeping enabled to be on or offvoidsetSleepTime(int sleepTime) Set the time spent asleepvoidsetTimeout(int millis) Set the timeout on the underlying sockets and other resources that may be used.voidsetTransferBufferSize(int size) Set the size of the buffers used in writing to and reading from the servervoidsetType(FTPTransferType type) Set the transfer typevoidSets the umask used to write permissionslongGet the size of a remote file.toString()String representationMethods inherited from class com.enterprisedt.net.ftp.ssh.SCPClient
checkConnection, connectSSH, disableAllAlgorithms, disableAllAlgorithms, executeCommand, executeCommand, getConnectionProperties, getDeleteCount, getDownloadCount, getEnabledAlgorithms, getEnabledAlgorithms, getHostPublicKey, getId, getNetworkBufferSize, getProxySettings, getRemoteHost, getRemotePort, getTimeout, getTransportProvider, getUploadCount, getValidator, isAlgorithmEnabled, isRekeyEnabled, resetDeleteCount, resetDownloadCount, resetUploadCount, setAlgorithmEnabled, setAuthentication, setAuthentication, setAuthentication, setAuthentication, setAuthentication, setAuthentication, setAuthentication, setAuthenticationChangePassword, setConnectionProperties, setId, setNetworkBufferSize, setProxyParams, setRekeyEnabled, setRekeyTransferLimit, setRemoteHost, setRemotePort, setTransportProvider, setValidator, system, validateAlgorithmsMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface com.enterprisedt.net.ftp.FTPClientInterface
executeCommand, getDeleteCount, getDownloadCount, getId, getNetworkBufferSize, getRemoteHost, getRemotePort, getTimeout, getUploadCount, resetDeleteCount, resetDownloadCount, resetUploadCount, setId, setNetworkBufferSize, setRemoteHost, setRemotePort, systemMethods inherited from interface com.enterprisedt.net.ftp.pro.ProFTPClientInterface
getProxySettings
-
Field Details
-
DEFAULT_ENCODING
Default encoding used for control data- See Also:
-
EOL_CRLF
Carriage return + line feed end of line marker- See Also:
-
EOL_LF
Line feed end of line marker- See Also:
-
-
Constructor Details
-
SSHFTPClient
public SSHFTPClient()Constructs an SFTP client. The class description describes how to use the SFTP client to obtain a connection with a remote host.
-
-
Method Details
-
setSCPMode
public void setSCPMode(boolean on) Set the SCP mode. If SCP mode is set, only SCP operations are permitted- Parameters:
on- ture for SCP mode, false for SFTP mode (the default)
-
isSCPMode
public boolean isSCPMode()- Returns:
- true if in SCP mode
-
setConfigFlags
Set the configuration flags. Can only be called if not currently connected.- Parameters:
configFlags- configuration flags to set- Throws:
FTPException
-
getConfigFlags
public int getConfigFlags()Get the set configuration flags.- Returns:
- configuration flags
-
isParallelMode
public boolean isParallelMode()Is the client in parallel write mode, which is the default- Returns:
- true if in parallel mode
-
setParallelMode
public void setParallelMode(boolean parallelWriteMode) Switch parallel write mode on or off- Parameters:
parallelWriteMode- true for on, false for off
-
getMaxQueuedReadRequests
public int getMaxQueuedReadRequests()- Returns:
- the maximum number of requests to send
-
setMaxQueuedReadRequests
public void setMaxQueuedReadRequests(int maxQueuedReadRequests) In SFTP, files are read block-by-block. The client sends one request per block. Queueing up read-requests helps to counteract latencies. This property determines the number of read-requests that should be queued up. If it's set to 1 then no requests are queued up meaning that reads are done synchronously. The default is 32.- Parameters:
maxQueuedReadRequests- the maximum number of requests to send
-
checkDirReadableForChDir
public boolean checkDirReadableForChDir()Check that a directory is readable prior to changing into it- Returns:
- true if we perform the readable check, false otherwise
-
setCheckDirReadableForChDir
public void setCheckDirReadableForChDir(boolean checkDirReadableForChDir) Set the check for directory readability prior to changing the directory on or off- Parameters:
checkDirReadableForChDir- true if checking for readability
-
getFileLockingEnabled
public boolean getFileLockingEnabled()Determine if file locking on local downloaded files is being used or not. Default is true.- Specified by:
getFileLockingEnabledin interfaceFTPClientInterface- Returns:
- true if file locking is enabled, false otherwise
-
setFileLockingEnabled
public void setFileLockingEnabled(boolean fileLockingEnabled) 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.- Specified by:
setFileLockingEnabledin interfaceFTPClientInterface- Parameters:
fileLockingEnabled- true to enable locking, false to disable
-
setMaxTransferRate
public void setMaxTransferRate(int thresholdBytesPerSecond) Set the maximum transfer rates in bytes per sec- Specified by:
setMaxTransferRatein interfaceProFTPClientInterface- Parameters:
thresholdBytesPerSecond- maximum bytes per second to transfer
-
getMaxTransferRate
public int getMaxTransferRate()Get the maximum bandwidth for transfers- Specified by:
getMaxTransferRatein interfaceProFTPClientInterface- Returns:
- threshold bytes per second, or -1 if no threshold
-
getServerResponseTimeout
public long getServerResponseTimeout()Deprecated.Get the timeout used for server responses.- Returns:
- timeout in milliseconds
-
setServerResponseTimeout
Deprecated.UsesetTimeout(int)Set the server response timeout. Must be called before connecting.- Parameters:
serverResponseTimeout- server response timeout in milliseconds- Throws:
FTPException
-
setControlEncoding
Set the encoding. Can only do this if not connected- Specified by:
setControlEncodingin interfaceFTPClientInterface- Parameters:
controlEncoding- The controlEncoding to set, which is the name of a Charset- Throws:
FTPException- See Also:
-
getHostPublicKey
Helper method that may be used to obtain a server's public key without instantiating anSSHFTPClient. This method returns anSSHFTPPublicKeyobject whoseSSHFTPPublicKey.write(OutputStream, int)method may be used to write the public key to a file. The method will returnnullif a public key could not be retrieved. Logging may be used to discover any connection problems. If more advanced settings are required then an instance ofSSHFTPClientshould be used.- Parameters:
remoteHost- Address of the server whose public key is to be fetched.- Returns:
- An instance of
SSHFTPPublicKeyrepresenting - Throws:
FTPException
-
getHostPublicKey
public static SSHFTPPublicKey getHostPublicKey(String remoteHost, int remotePort) throws FTPException Helper method that may be used to obtain a server's public key without instantiating anSSHFTPClient. This method returns anSSHFTPPublicKeyobjectSSHFTPPublicKey.write(OutputStream,int)method may be used to write the public key to a file. The method will returnnullif a public key could not be retrieved. Logging may be used to discover any connection problems. If more advanced settings are required then an instance ofSSHFTPClientshould be used.- Parameters:
remoteHost- Address of the server whose public key is to be fetched.remotePort- Port of the server whose public key is to be fetched.- Returns:
- An instance of
SSHFTPPublicKeyrepresenting - Throws:
FTPException
-
setTimeout
Description copied from interface:FTPClientInterfaceSet 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).- Specified by:
setTimeoutin interfaceFTPClientInterface- Overrides:
setTimeoutin classSCPClient- Parameters:
millis- The length of the timeout, in milliseconds- Throws:
FTPException
-
setDetectTransferMode
public void setDetectTransferMode(boolean detectTransferMode) Description copied from interface:FTPClientInterfaceSet 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- Specified by:
setDetectTransferModein interfaceFTPClientInterface- Parameters:
detectTransferMode- true if detecting transfer mode, false if not
-
getDetectTransferMode
public boolean getDetectTransferMode()Description copied from interface:FTPClientInterfaceGet the detect transfer mode- Specified by:
getDetectTransferModein interfaceFTPClientInterface- Returns:
- true if we are detecting binary and ASCII transfers from the file type
-
getMaxPacketSize
public int getMaxPacketSize()Get the max packet size set- Returns:
- the default if not set, or else the set size
-
setMaxPacketSize
Set the maximum packet size. This should be used if errors are being received such as "packet too long: xxxx". Set the size smaller than the size listed in the error message. Note - must be set before connect() is called. Changing the packet size can also dramatically affect performance.- Parameters:
maxPacketSize- size to set- Throws:
FTPException
-
setTransferBufferSize
public void setTransferBufferSize(int size) Set the size of the buffers used in writing to and reading from the server- Parameters:
size- new size of buffer in bytes
-
getTransferBufferSize
public int getTransferBufferSize()Get the size of the buffers used in writing to and reading from the server- Returns:
- transfer buffer size
-
setRemoteEOL
Set a remoteEOL to be forced, irrespective of what is detected from server information. This method must be called before connecting.- Parameters:
remoteEOL- remoteEOL to force
-
getRemoteEOL
Get the remote EOL string that is forced to be used irrespective of what is detected from server information.- Returns:
- String, or null if autodetect is to be used
-
getType
Description copied from interface:FTPClientInterfaceGet the current transfer type- Specified by:
getTypein interfaceFTPClientInterface- Returns:
- the current type of the transfer, i.e. BINARY or ASCII
-
setType
Description copied from interface:FTPClientInterfaceSet the transfer type- Specified by:
setTypein interfaceFTPClientInterface- Parameters:
type- the transfer type to set the server to
-
getSFTPSubsystemPath
Returns the server-side path of the SFTP subsystem (default is null). The SFTP subsystem path should usually only be set if the SSH server has not configured properly. By default this method returnsnull, which causes thesftpsubsystem to be used.- Returns:
- path of the SFTP subsystem on the server (default is null).
-
setSFTPSubsystemPath
Sets the server-side path of the SFTP subsystem (default is null). The SFTP subsystem path should usually only be set if the SSH server has not configured properly. By default this value isnull, which causes thesftpsubsystem to be used. Setting this property is equivalent to using the-soption on the OpenSSH sftp console command.- Parameters:
sftpSubsystemPath- path of the SFTP subsystem on the server.
-
resumeNextDownload
Resumes the next download from the offset point, which must be smaller than the length of the file to be downloaded.- Specified by:
resumeNextDownloadin interfaceFTPClientInterface- Parameters:
offset- offset bytes are skipped before downloading the file.- Throws:
FTPException
-
resume
Description copied from interface:FTPClientInterfaceMake 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).- Specified by:
resumein interfaceFTPClientInterface- Throws:
FTPException
-
cancelResume
Description copied from interface:FTPClientInterfaceCancel the resume. Use this method if something goes wrong and the server is left in an inconsistent state- Specified by:
cancelResumein interfaceFTPClientInterface- Throws:
IOExceptionFTPException
-
cancelTransfer
public void cancelTransfer()Description copied from interface:FTPClientInterfaceCancels 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.- Specified by:
cancelTransferin interfaceFTPClientInterface
-
isTransferCancelled
public boolean isTransferCancelled()Has the current transfer been cancelled?- Returns:
- true if cancel, false otherwise
-
connect
Connects to the server at the address and port number defined in the constructor. Please refer to the class description for information on configuration steps that must be taken before this method is called.- Specified by:
connectin interfaceFTPClientInterface- Overrides:
connectin classSCPClient- Throws:
IOException- Thrown if there is a TCP/IP-related error.FTPException- Thrown if client is already connected or if there is a configuration error, or if a connection could not be established.
-
getDetectedRemoteEOL
Get the EOL detected by the client- Returns:
-
connected
public boolean connected()Is the client currently connected?- Specified by:
connectedin interfaceFTPClientInterface- Overrides:
connectedin classSCPClient- Returns:
- true if connected, false otherwise
-
setProgressMonitor
Description copied from interface:FTPClientInterfaceSet 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.- Specified by:
setProgressMonitorin interfaceFTPClientInterface- Parameters:
monitor- the monitor objectinterval- bytes transferred in between callbacks
-
setProgressMonitor
Description copied from interface:FTPClientInterfaceSet a progress monitor for callbacks. Uses default callback interval- Specified by:
setProgressMonitorin interfaceFTPClientInterface- Parameters:
monitor- the monitor object
-
getMonitorInterval
public long getMonitorInterval()Description copied from interface:FTPClientInterfaceGet the bytes transferred between each callback on the progress monitor- Specified by:
getMonitorIntervalin interfaceFTPClientInterface- Returns:
- long bytes to be transferred before a callback
-
setMonitorInterval
public void setMonitorInterval(long interval) Set the progress monitor interval for notifications- Specified by:
setMonitorIntervalin interfaceProFTPClientInterface- Parameters:
interval- notification interval
-
getProgressMonitor
Get the reference to the progress monitor- Returns:
- progress monitor
-
getProgressMonitorEx
Get reference to the transfer listener- Specified by:
getProgressMonitorExin interfaceProFTPClientInterface- Returns:
- FTPProgressMonitorEx
-
setProgressMonitorEx
Set reference to the transfer listener- Specified by:
setProgressMonitorExin interfaceProFTPClientInterface- Parameters:
monitorEx- transfer listener
-
size
Description copied from interface:FTPClientInterfaceGet 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)- Specified by:
sizein interfaceFTPClientInterface- Parameters:
remoteFile- name or path of remote file in current directory- Returns:
- size of file in bytes
- Throws:
IOExceptionFTPException
-
put
Description copied from class:SCPClientUpload a file.- Specified by:
putin interfaceFTPClientInterface- Overrides:
putin classSCPClient- Parameters:
localPath- path of local file to be uploadedremoteFile- path of remote file to upload to- Returns:
- The name of the remote file - normally the name supplied, or else the unique name generated by the server.
- Throws:
IOExceptionFTPException
-
put
public String put(String localPath, String remoteFile, boolean append) throws IOException, FTPException Description copied from interface:FTPClientInterfacePut 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.- Specified by:
putin interfaceFTPClientInterface- 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
-
put
Description copied from interface:FTPClientInterfacePut 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.- Specified by:
putin interfaceFTPClientInterface- 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
public String put(InputStream srcStream, String remoteFile, boolean append) throws IOException, FTPException Description copied from interface:FTPClientInterfacePut 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.- Specified by:
putin interfaceFTPClientInterface- 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
Description copied from interface:FTPClientInterfacePut 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.- Specified by:
putin interfaceFTPClientInterface- 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
Description copied from interface:FTPClientInterfacePut 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.- Specified by:
putin interfaceFTPClientInterface- 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
-
get
Description copied from class:SCPClientDownload a file- Specified by:
getin interfaceFTPClientInterface- Overrides:
getin classSCPClient- Parameters:
localPath- path of local file to download toremoteFile- path of remote file- Throws:
IOExceptionFTPException
-
get
Description copied from interface:FTPClientInterfaceGet data from the FTP server. Uses the currently set transfer mode.- Specified by:
getin interfaceFTPClientInterface- Parameters:
destStream- data stream to write data toremoteFile- name of remote file in current directory- Throws:
IOExceptionFTPException
-
get
Description copied from interface:FTPClientInterfaceGet 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.- Specified by:
getin interfaceFTPClientInterface- Parameters:
remoteFile- name of remote file in current directory- Throws:
IOExceptionFTPException
-
fileDetails
Get details about the named file- Parameters:
name- name of a file- Returns:
- if it exists, an FTPFile object
- Throws:
IOExceptionFTPException
-
dirDetails
public void dirDetails(String dirname, DirectoryListCallback lister) throws IOException, FTPException, ParseException Description copied from interface:FTPClientInterfaceList 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.- Specified by:
dirDetailsin interfaceFTPClientInterface- Parameters:
dirname- name of directory (some servers permit a filemask)lister- callback to be notified of errors- Throws:
IOExceptionFTPExceptionParseException
-
dirDetails
Description copied from interface:FTPClientInterfaceList 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).- Specified by:
dirDetailsin interfaceFTPClientInterface- Parameters:
dirname- name of directory (some servers permit a filemask)- Returns:
- an array of FTPFile objects
- Throws:
IOExceptionFTPExceptionParseException
-
dir
Description copied from interface:FTPClientInterfaceList 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.- Specified by:
dirin interfaceFTPClientInterface- Returns:
- an array of current directory listing strings
- Throws:
IOExceptionFTPException
-
dir
Description copied from interface:FTPClientInterfaceList 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.- Specified by:
dirin interfaceFTPClientInterface- Parameters:
dirname- name of directory OR filemask- Returns:
- an array of directory listing strings
- Throws:
IOExceptionFTPException
-
dir
Description copied from interface:FTPClientInterfaceList 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.- Specified by:
dirin interfaceFTPClientInterface- Parameters:
dirname- name of directory OR filemaskfull- true if detailed listing required false otherwise- Returns:
- an array of directory listing strings
- Throws:
IOExceptionFTPException
-
delete
Description copied from interface:FTPClientInterfaceDelete the specified remote file- Specified by:
deletein interfaceFTPClientInterface- Parameters:
remoteFile- name of remote file to delete- Throws:
IOExceptionFTPException
-
rename
Description copied from interface:FTPClientInterfaceRename a file or directory- Specified by:
renamein interfaceFTPClientInterface- Parameters:
from- name of file or directory to renameto- intended name- Throws:
IOExceptionFTPException
-
exists
Description copied from interface:FTPClientInterfaceDoes the named file exist in the current server directory?- Specified by:
existsin interfaceFTPClientInterface- Parameters:
remoteFile- name of remote file- Returns:
- true if exists, false otherwise
- Throws:
IOExceptionFTPException
-
rmdir
Description copied from interface:FTPClientInterfaceDelete the specified remote working directory- Specified by:
rmdirin interfaceFTPClientInterface- Parameters:
dir- name of remote directory to delete- Throws:
IOExceptionFTPException
-
mkdir
Description copied from interface:FTPClientInterfaceCreate the specified remote working directory- Specified by:
mkdirin interfaceFTPClientInterface- Parameters:
dir- name of remote directory to create- Throws:
IOExceptionFTPException
-
changeMode
Changes the access permissions or modes of the specified file or directory. Modes determine who can read, change or execute a file.Absolute modes are octal numbers specifying the complete list of attributes for the files; you specify attributes by OR'ing together these bits. These must be octal numbers as in the examples below. 0400 Individual read 0200 Individual write 0100 Individual execute (or list directory) 0040 Group read 0020 Group write 0010 Group execute 0004 Other read 0002 Other write 0001 Other execute
- Parameters:
permissions- the absolute mode of the file/directory. These must be in octal, i.e. they must be preceded with a '0'.path- the path to the file/directory on the remote server- Throws:
IOException- if an IO error occurs or the file if not foundFTPException
-
changeMode
Changes the access permissions or modes of the specified file or directory. Modes determine who can read, change or execute a file.Absolute modes are octal numbers specifying the complete list of attributes for the files; you specify attributes by OR'ing together these bits. These must be octal strings as in the examples below. 0400 Individual read 0200 Individual write 0100 Individual execute (or list directory) 0040 Group read 0020 Group write 0010 Group execute 0004 Other read 0002 Other write 0001 Other execute
- Parameters:
permissions- the absolute mode of the file/directory. These must be an octal stringpath- the path to the file/directory on the remote server- Throws:
IOException- if an IO error occurs or the file if not foundFTPException
-
changeGroup
Sets the group ID for the file or directory.- Parameters:
gid- the numeric group id for the new grouppath- the path to the remote file/directory- Throws:
IOException- if an IO error occurs or the file does not existFTPException
-
changeOwner
Sets the user ID to owner for the file or directory.- Parameters:
uid- numeric user id of the new ownerpath- the path to the remote file/directory- Throws:
IOException- if an IO error occurs or the file does not existFTPException
-
setUmask
Sets the umask used to write permissions- Parameters:
umask- umask as 4 digit octal, e.g. 0022- Throws:
FTPException
-
getUmask
Get the current umask- Returns:
- current umask as octal string
- Throws:
FTPException
-
chdir
Description copied from interface:FTPClientInterfaceChange the remote working directory to that supplied- Specified by:
chdirin interfaceFTPClientInterface- Parameters:
dir- name of remote directory to change to- Throws:
IOExceptionFTPException
-
cdup
Description copied from interface:FTPClientInterfaceChange the remote working directory to the parent directory- Specified by:
cdupin interfaceFTPClientInterface- Throws:
IOExceptionFTPException
-
modtime
Description copied from interface:FTPClientInterfaceGet 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.- Specified by:
modtimein interfaceFTPClientInterface- Parameters:
remoteFile- name of remote file- Throws:
IOExceptionFTPException
-
setModTime
Set the last modified time for the supplied file- Specified by:
setModTimein interfaceFTPClientInterface- Parameters:
path- the path to the file/directory on the remote servermodTime- the time stamp (UTC) of when it was last modified- Throws:
IOExceptionFTPException
-
pwd
Description copied from interface:FTPClientInterfaceGet the current remote working directory- Specified by:
pwdin interfaceFTPClientInterface- Returns:
- the current working directory
- Throws:
IOExceptionFTPException
-
mdelete
Description copied from interface:ProFTPClientInterfaceDeletes all files matching the wildcard in the current remote directory only- Specified by:
mdeletein interfaceProFTPClientInterface- Parameters:
wildcard-- Throws:
IOExceptionFTPExceptionParseException
-
mdelete
Description copied from interface:ProFTPClientInterfaceDeletes all files matching the filter in the current remote directory only- Specified by:
mdeletein interfaceProFTPClientInterface- Parameters:
filter- file filter- Throws:
IOExceptionFTPExceptionParseException
-
mdelete
public void mdelete(String remoteDir, String wildcard, boolean recurse) throws IOException, FTPException, ParseException Description copied from interface:ProFTPClientInterfaceDelete all the files in this directory (and its subdirectories if recurse is true) that match the supplied wildcard. No directories are deleted. Only files matching the wildcard are deleted. On Windows clients, case is ignored.- Specified by:
mdeletein interfaceProFTPClientInterface- Parameters:
remoteDir- name of remote directorywildcard- filename wildcardrecurse- if true, recurse through subdirectories- Throws:
IOExceptionFTPExceptionParseException
-
mdelete
public void mdelete(String remoteDir, FileFilter filter, boolean recurse) throws IOException, FTPException, ParseException Description copied from interface:ProFTPClientInterfaceDelete all the files in this directory (and its subdirectories if recurse is true) that match the supplied filter. No directories are deleted. Only files matching the wildcard are deleted. On Windows clients, case is ignored.- Specified by:
mdeletein interfaceProFTPClientInterface- Parameters:
remoteDir- name of remote directoryfilter- filename filterrecurse- if true, recurse through subdirectories- Throws:
IOExceptionFTPExceptionParseException
-
rmdir
public void rmdir(String remoteDir, boolean recurse) throws IOException, FTPException, ParseException Description copied from interface:ProFTPClientInterfaceDelete this remote directory. If recurse is true, delete all its contents, recursively going through subdirectories. If recurse is false and the directory contains files, an exception will be thrown- Specified by:
rmdirin interfaceProFTPClientInterface- Parameters:
remoteDir- name of remote directoryrecurse- if true, recurse through subdirectories- Throws:
IOExceptionFTPExceptionParseException
-
mput
Description copied from interface:ProFTPClientInterfacePut all files matching the wildcard in the supplied local directory only into the current remote directory- Specified by:
mputin interfaceProFTPClientInterface- Parameters:
localDir- local directory to get files fromwildcard- filename wildcard- Throws:
IOExceptionFTPException
-
mput
Description copied from interface:ProFTPClientInterfacePut all files matching the wildcard in the supplied local directory only into the current remote directory- Specified by:
mputin interfaceProFTPClientInterface- Parameters:
localDir- local directory to get files fromfilter- filename filter- Throws:
IOExceptionFTPException
-
mput
public void mput(String localDir, String remoteDir, String wildcard, boolean recurse) throws FTPException, IOException Description copied from interface:ProFTPClientInterfacePuts this entire directory and its contents. If recurse is true, recursively go through the local directory supplied (which can be relative or absolute), including subdirectories. Puts the directory into the current remote directory, into a directory with the supplied remoteDir name.- Specified by:
mputin interfaceProFTPClientInterface- Parameters:
localDir- name of local directoryremoteDir- name of remote directorywildcard- filename wildcardrecurse- if true recurse into subdirectories- Throws:
FTPExceptionIOException
-
mput
public void mput(String localDir, String remoteDir, FileFilter filter, boolean recurse) throws FTPException, IOException Description copied from interface:ProFTPClientInterfacePuts this entire directory and its contents. If recurse is true, recursively go through the local directory supplied (which can be relative or absolute), including subdirectories. Puts the directory into the current remote directory, into a directory with the supplied remoteDir name.- Specified by:
mputin interfaceProFTPClientInterface- Parameters:
localDir- name of local directoryremoteDir- name of remote directoryfilter- filename filterrecurse- if true recurse into subdirectories- Throws:
FTPExceptionIOException
-
mget
Description copied from interface:ProFTPClientInterfaceGet all files matching the filter in the current remote directory only into the supplied local directory- Specified by:
mgetin interfaceProFTPClientInterface- Parameters:
localDir- local directory to get files fromwildcard- filename wildcard- Throws:
IOExceptionFTPExceptionParseException
-
mget
public void mget(String localDir, FileFilter filter) throws IOException, FTPException, ParseException Description copied from interface:ProFTPClientInterfaceGet all files matching the filter in the current remote directory only into the supplied local directory- Specified by:
mgetin interfaceProFTPClientInterface- Parameters:
localDir- local directory to get files fromfilter- filename filter- Throws:
IOExceptionFTPExceptionParseException
-
mget
public void mget(String localDir, String remoteDir, String wildcard, boolean recurse) throws FTPException, IOException, ParseException Description copied from interface:ProFTPClientInterfaceGets this entire remote directory and its contents, recursively going through the remote directory name supplied. Gets the directory into the current local directory, into a directory with supplied localDir name- Specified by:
mgetin interfaceProFTPClientInterface- Parameters:
localDir- name of local directory we are transferring intoremoteDir- name of remote directorywildcard- filename wildcardrecurse- if true recurse into subdirectories- Throws:
FTPExceptionIOExceptionParseException
-
mget
public void mget(String localDir, String remoteDir, FileFilter filter, boolean recurse) throws FTPException, IOException, ParseException Description copied from interface:ProFTPClientInterfaceGets this entire remote directory and its contents, recursively going through the remote directory name supplied. Gets the directory into the current local directory, into a directory with supplied localDir name- Specified by:
mgetin interfaceProFTPClientInterface- Parameters:
localDir- name of local directory we are transferring intoremoteDir- name of remote directoryfilter- filename filterrecurse- if true recurse into subdirectories- Throws:
FTPExceptionIOExceptionParseException
-
getCountBeforeSleep
public int getCountBeforeSleep()Description copied from interface:ProFTPClientInterfaceGet the number of transfers set before sleeping- Specified by:
getCountBeforeSleepin interfaceProFTPClientInterface- Returns:
- integer
-
setCountBeforeSleep
public void setCountBeforeSleep(int countBeforeSleep) Description copied from interface:ProFTPClientInterfaceSet the number of transfers required before sleeping- Specified by:
setCountBeforeSleepin interfaceProFTPClientInterface- Parameters:
countBeforeSleep- maximum transfer count
-
isSleepEnabled
public boolean isSleepEnabled()Description copied from interface:ProFTPClientInterfaceIs sleeping enabled?- Specified by:
isSleepEnabledin interfaceProFTPClientInterface- Returns:
- true if enabled
-
setSleepEnabled
public void setSleepEnabled(boolean sleepEnabled) Description copied from interface:ProFTPClientInterfaceSet sleeping enabled to be on or off- Specified by:
setSleepEnabledin interfaceProFTPClientInterface- Parameters:
sleepEnabled- if true, sleeping is enabled, otherwise it is switched off
-
getSleepTime
public int getSleepTime()Description copied from interface:ProFTPClientInterfaceGet the number of seconds spent asleep- Specified by:
getSleepTimein interfaceProFTPClientInterface- Returns:
- integer
-
setSleepTime
public void setSleepTime(int sleepTime) Description copied from interface:ProFTPClientInterfaceSet the time spent asleep- Specified by:
setSleepTimein interfaceProFTPClientInterface- Parameters:
sleepTime- sleep time in seconds
-
keepAlive
Tries to keep the current connection alive by sending an innocuous command to signal that the client is still active- Specified by:
keepAlivein interfaceFTPClientInterface- Throws:
IOExceptionFTPException
-
quit
Description copied from interface:FTPClientInterfaceQuit the FTP session- Specified by:
quitin interfaceFTPClientInterface- Overrides:
quitin classSCPClient- Throws:
IOExceptionFTPException
-
quitImmediately
Description copied from interface:FTPClientInterfaceQuit the FTP session immediately. If a transfer is underway it will be terminated.- Specified by:
quitImmediatelyin interfaceFTPClientInterface- Overrides:
quitImmediatelyin classSCPClient- Throws:
IOExceptionFTPException
-
toString
String representation
-
SCPClient.getTimeout()