com.enterprisedt.net.ftp.ssh
Class SSHFTPClient

java.lang.Object
  extended by com.enterprisedt.net.ftp.ssh.SCPClient
      extended by com.enterprisedt.net.ftp.ssh.SSHFTPClient
All Implemented Interfaces:
FTPClientInterface, ProFTPClientInterface

public class SSHFTPClient
extends SCPClient
implements 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:

  1. 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); 
     
  2. 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");
     
  3. 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:

  1. User-name/Password Authentication involves simply passing a user-name/password to the server for authentication. This is set up simply by by calling setAuthentication as follows:
       ftpClient.setAuthentication("jack", "my_ftp_password");
     
  2. 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: 1.50 $
Author:
Hans Andersen

Nested Class Summary
static class SSHFTPClient.ConfigFlags
          ConfigFlags contains various static integers which are used to configure clients.
 
Field Summary
static java.lang.String DEFAULT_ENCODING
          Default encoding used for control data
static java.lang.String EOL_CRLF
          Carriage return + line feed end of line marker
static java.lang.String EOL_LF
          Line feed end of line marker
 
Fields inherited from class com.enterprisedt.net.ftp.ssh.SCPClient
authenticator, connProps, DEFAULT_PORT, deleteCount, downloadCount, expectedProduct, id, license, retryAuthenticator, ssh, uploadCount, validator
 
Fields inherited from interface com.enterprisedt.net.ftp.pro.ProFTPClientInterface
cvsId
 
Constructor Summary
SSHFTPClient()
          Constructs an SFTP client.
 
Method Summary
 void cancelResume()
          Cancel the resume.
 void cancelTransfer()
          Cancels the current transfer.
 void cdup()
          Change the remote working directory to the parent directory
 void changeGroup(int gid, java.lang.String path)
          Sets the group ID for the file or directory.
 void changeMode(int permissions, java.lang.String path)
          Changes the access permissions or modes of the specified file or directory.
 void changeOwner(int uid, java.lang.String path)
          Sets the user ID to owner for the file or directory.
 void chdir(java.lang.String dir)
          Change the remote working directory to that supplied
 void connect()
          Connects to the server at the address and port number defined in the constructor.
 boolean connected()
          Is the client currently connected?
 void delete(java.lang.String remoteFile)
          Delete the specified remote file
 java.lang.String[] dir()
          List current directory's contents as an array of strings of filenames.
 java.lang.String[] dir(java.lang.String dirname)
          List a directory's contents as an array of strings of filenames.
 java.lang.String[] dir(java.lang.String dirname, boolean full)
          List a directory's contents as an array of strings.
 FTPFile[] dirDetails(java.lang.String dirname)
          List a directory's contents as an array of FTPFile objects.
 boolean exists(java.lang.String remoteFile)
          Does the named file exist in the current server directory?
 void get(java.io.OutputStream destStream, java.lang.String remoteFile)
          Get data from the FTP server.
 byte[] get(java.lang.String remoteFile)
          Get data from the FTP server.
 void get(java.lang.String localPath, java.lang.String remoteFile)
          Download a file
 int getConfigFlags()
          Get the set configuration flags.
 int getCountBeforeSleep()
          Get the number of transfers set before sleeping
 java.lang.String getDetectedRemoteEOL()
          Get the EOL detected by the client
 boolean getDetectTransferMode()
          Get the detect transfer mode
static SSHFTPPublicKey getHostPublicKey(java.lang.String remoteHost)
          Helper method that may be used to obtain a server's public key without instantiating an SSHFTPClient.
static SSHFTPPublicKey getHostPublicKey(java.lang.String remoteHost, int remotePort)
          Helper method that may be used to obtain a server's public key without instantiating an SSHFTPClient.
 int getMaxPacketSize()
          Get the max packet size set
 long getMonitorInterval()
          Get the bytes transferred between each callback on the progress monitor
 FTPProgressMonitor getProgressMonitor()
          Get the reference to the progress monitor
 java.lang.String getRemoteEOL()
          Get the remote EOL string that is forced to be used irrespective of what is detected from server information.
 long getServerResponseTimeout()
          Deprecated. Use SCPClient.getTimeout()
 java.lang.String getSFTPSubsystemPath()
          Returns the server-side path of the SFTP subsystem (default is null).
 int getSleepTime()
          Get the number of seconds spent asleep
 int getTransferBufferSize()
          Get the size of the buffers used in writing to and reading from the server
 FTPTransferType getType()
          Get the current transfer type
 java.lang.String getUmask()
          Get the current umask
 boolean isSleepEnabled()
          Is sleeping enabled?
 boolean isTransferCancelled()
          Has the current transfer been cancelled?
 void keepAlive()
          Tries to keep the current connection alive by sending an innocuous commmand to signal that the client is still active
 void mdelete(java.io.FileFilter filter)
          Deletes all files matching the filter in the current remote directory only
 void mdelete(java.lang.String wildcard)
          Deletes all files matching the wildcard in the current remote directory only
 void mdelete(java.lang.String remoteDir, java.io.FileFilter filter, boolean recurse)
          Delete all the files in this directory (and its subdirectories if recurse is true) that match the supplied filter.
 void mdelete(java.lang.String remoteDir, java.lang.String wildcard, boolean recurse)
          Delete all the files in this directory (and its subdirectories if recurse is true) that match the supplied wildcard.
 void mget(java.lang.String localDir, java.io.FileFilter filter)
          Get all files matching the filter in the current remote directory only into the supplied local directory
 void mget(java.lang.String localDir, java.lang.String wildcard)
          Get all files matching the filter in the current remote directory only into the supplied local directory
 void mget(java.lang.String localDir, java.lang.String remoteDir, java.io.FileFilter filter, boolean recurse)
          Gets this entire remote directory and its contents, recursively going through the remote directory name supplied.
 void mget(java.lang.String localDir, java.lang.String remoteDir, java.lang.String wildcard, boolean recurse)
          Gets this entire remote directory and its contents, recursively going through the remote directory name supplied.
 void mkdir(java.lang.String dir)
          Create the specified remote working directory
 java.util.Date modtime(java.lang.String remoteFile)
          Get modification time for a remote file.
 void mput(java.lang.String localDir, java.io.FileFilter filter)
          Put all files matching the wildcard in the supplied local directory only into the current remote directory
 void mput(java.lang.String localDir, java.lang.String wildcard)
          Put all files matching the wildcard in the supplied local directory only into the current remote directory
 void mput(java.lang.String localDir, java.lang.String remoteDir, java.io.FileFilter filter, boolean recurse)
          Puts this entire directory and its contents.
 void mput(java.lang.String localDir, java.lang.String remoteDir, java.lang.String wildcard, boolean recurse)
          Puts this entire directory and its contents.
 java.lang.String put(byte[] bytes, java.lang.String remoteFile)
          Put data onto the FTP server.
 java.lang.String put(byte[] bytes, java.lang.String remoteFile, boolean append)
          Put data onto the FTP server.
 java.lang.String put(java.io.InputStream srcStream, java.lang.String remoteFile)
          Put a stream of data onto the FTP server.
 java.lang.String put(java.io.InputStream srcStream, java.lang.String remoteFile, boolean append)
          Put a stream of data onto the FTP server.
 java.lang.String put(java.lang.String localPath, java.lang.String remoteFile)
          Upload a file.
 java.lang.String put(java.lang.String localPath, java.lang.String remoteFile, boolean append)
          Put a local file onto the FTP server.
 java.lang.String pwd()
          Get the current remote working directory
 void quit()
          Quit the FTP session
 void quitImmediately()
          Quit the FTP session immediately.
 void rename(java.lang.String from, java.lang.String to)
          Rename a file or directory
 void resume()
          Make the next file transfer (put or get) resume.
 void rmdir(java.lang.String dir)
          Delete the specified remote working directory
 void rmdir(java.lang.String remoteDir, boolean recurse)
          Delete this remote directory.
 void setConfigFlags(int configFlags)
          Set the configuration flags.
 void setControlEncoding(java.lang.String controlEncoding)
          Set the encoding.
 void setCountBeforeSleep(int countBeforeSleep)
          Set the number of transfers required before sleeping
 void setDetectTransferMode(boolean detectTransferMode)
          Set autodetect of filetypes on or off.
 void setMaxPacketSize(int maxPacketSize)
          Set the maximum packet size.
 void setModTime(java.lang.String path, java.util.Date modTime)
          Set the last modified time for the supplied file
 void setMonitorInterval(long interval)
          Set the progress monitor interval for notifications
 void setProgressMonitor(FTPProgressMonitor monitor)
          Set a progress monitor for callbacks.
 void setProgressMonitor(FTPProgressMonitor monitor, long interval)
          Set a progress monitor for callbacks.
 void setRemoteEOL(java.lang.String remoteEOL)
          Set a remoteEOL to be forced, irrespective of what is detected from server information
 void setServerResponseTimeout(long serverResponseTimeout)
          Deprecated. Use setTimeout(int)
 void setSFTPSubsystemPath(java.lang.String sftpSubsystemPath)
          Sets the server-side path of the SFTP subsystem (default is null).
 void setSleepEnabled(boolean sleepEnabled)
          Set sleeping enabled to be on or off
 void setSleepTime(int sleepTime)
          Set the time spent asleep
 void setTimeout(int millis)
          Set the TCP timeout on the underlying socket(s).
 void setTransferBufferSize(int size)
          Set the size of the buffers used in writing to and reading from the server
 void setType(FTPTransferType type)
          Set the transfer type
 void setUmask(java.lang.String umask)
          Sets the umask used to write permissions
 long size(java.lang.String remoteFile)
          Get the size of a remote file.
 java.lang.String toString()
          String representation
 
Methods inherited from class com.enterprisedt.net.ftp.ssh.SCPClient
checkConnection, connectSSH, disableAllAlgorithms, disableAllAlgorithms, executeCommand, getDeleteCount, getDownloadCount, getEnabledAlgorithms, getEnabledAlgorithms, getHostPublicKey, getId, getRemoteHost, getRemotePort, getTimeout, getTransportProvider, getUploadCount, getValidator, isAlgorithmEnabled, resetDeleteCount, resetDownloadCount, resetUploadCount, setAlgorithmEnabled, setAuthentication, setAuthentication, setAuthentication, setAuthentication, setAuthentication, setId, setProxyParams, setRemoteHost, setRemotePort, setTransportProvider, setValidator, system, validateAlgorithms
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface com.enterprisedt.net.ftp.FTPClientInterface
executeCommand, getDeleteCount, getDownloadCount, getId, getRemoteHost, getRemotePort, getTimeout, getUploadCount, resetDeleteCount, resetDownloadCount, resetUploadCount, setId, setRemoteHost, setRemotePort, system
 

Field Detail

DEFAULT_ENCODING

public static final java.lang.String DEFAULT_ENCODING
Default encoding used for control data

See Also:
Constant Field Values

EOL_CRLF

public static final java.lang.String EOL_CRLF
Carriage return + line feed end of line marker

See Also:
Constant Field Values

EOL_LF

public static final java.lang.String EOL_LF
Line feed end of line marker

See Also:
Constant Field Values
Constructor Detail

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 Detail

setConfigFlags

public void setConfigFlags(int configFlags)
                    throws FTPException
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

getServerResponseTimeout

public long getServerResponseTimeout()
Deprecated. Use SCPClient.getTimeout()

Get the timeout used for server responses.

Returns:
timeout in milliseconds

setServerResponseTimeout

public void setServerResponseTimeout(long serverResponseTimeout)
                              throws FTPException
Deprecated. Use setTimeout(int)

Set the server response timeout. Must be called before connecting.

Parameters:
serverResponseTimeout - server response timeout in milliseconds
Throws:
FTPException

setControlEncoding

public void setControlEncoding(java.lang.String controlEncoding)
                        throws FTPException
Set the encoding. Can only do this if not connected

Specified by:
setControlEncoding in interface FTPClientInterface
Parameters:
controlEncoding - The controlEncoding to set, which is the name of a Charset
Throws:
FTPException
See Also:
Charset

getHostPublicKey

public static SSHFTPPublicKey getHostPublicKey(java.lang.String remoteHost)
                                        throws FTPException
Helper method that may be used to obtain a server's public key without instantiating an SSHFTPClient. This method returns an SSHFTPPublicKey object whose SSHFTPPublicKey.write(OutputStream, int) method may be used to write the public key to a file. The method will return null if 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 of SSHFTPClient should be used.

Parameters:
remoteHost - Address of the server whose public key is to be fetched.
Returns:
An instance of SSHFTPPublicKey representing
Throws:
FTPException

getHostPublicKey

public static SSHFTPPublicKey getHostPublicKey(java.lang.String remoteHost,
                                               int remotePort)
                                        throws FTPException
Helper method that may be used to obtain a server's public key without instantiating an SSHFTPClient. This method returns an SSHFTPPublicKey object SSHFTPPublicKey.write(OutputStream,int) method may be used to write the public key to a file. The method will return null if 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 of SSHFTPClient should 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 SSHFTPPublicKey representing
Throws:
FTPException

setTimeout

public void setTimeout(int millis)
                throws FTPException
Description copied from interface: FTPClientInterface
Set the TCP timeout on the underlying socket(s). 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 killed with a java.io.InterruptedException. The default is 0 meaning that the connection never times out.

Specified by:
setTimeout in interface FTPClientInterface
Overrides:
setTimeout in class SCPClient
Parameters:
millis - The length of the timeout, in milliseconds
Throws:
FTPException

setDetectTransferMode

public void setDetectTransferMode(boolean detectTransferMode)
Description copied from interface: FTPClientInterface
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

Specified by:
setDetectTransferMode in interface FTPClientInterface
Parameters:
detectTransferMode - true if detecting transfer mode, false if not

getDetectTransferMode

public boolean getDetectTransferMode()
Description copied from interface: FTPClientInterface
Get the detect transfer mode

Specified by:
getDetectTransferMode in interface FTPClientInterface
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:
-1 if not set, or else the set size

setMaxPacketSize

public void setMaxPacketSize(int maxPacketSize)
                      throws FTPException
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.

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

public void setRemoteEOL(java.lang.String remoteEOL)
Set a remoteEOL to be forced, irrespective of what is detected from server information

Parameters:
remoteEOL - remoteEOL to force

getRemoteEOL

public java.lang.String 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

public FTPTransferType getType()
Description copied from interface: FTPClientInterface
Get the current transfer type

Specified by:
getType in interface FTPClientInterface
Returns:
the current type of the transfer, i.e. BINARY or ASCII

setType

public void setType(FTPTransferType type)
Description copied from interface: FTPClientInterface
Set the transfer type

Specified by:
setType in interface FTPClientInterface
Parameters:
type - the transfer type to set the server to

getSFTPSubsystemPath

public java.lang.String 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 returns null, which causes the sftp subsystem to be used.

Returns:
path of the SFTP subsystem on the server (default is null).

setSFTPSubsystemPath

public void setSFTPSubsystemPath(java.lang.String sftpSubsystemPath)
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 is null, which causes the sftp subsystem to be used. Setting this property is equivalent to using the -s option on the OpenSSH sftp console command.

Parameters:
sftpSubsystemPath - path of the SFTP subsystem on the server.

resume

public void resume()
            throws FTPException
Description copied from interface: FTPClientInterface
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).

Specified by:
resume in interface FTPClientInterface
Throws:
FTPException

cancelResume

public void cancelResume()
                  throws java.io.IOException,
                         FTPException
Description copied from interface: FTPClientInterface
Cancel the resume. Use this method if something goes wrong and the server is left in an inconsistent state

Specified by:
cancelResume in interface FTPClientInterface
Throws:
java.io.IOException
FTPException

cancelTransfer

public void cancelTransfer()
Description copied from interface: FTPClientInterface
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.

Specified by:
cancelTransfer in interface FTPClientInterface

isTransferCancelled

public boolean isTransferCancelled()
Has the current transfer been cancelled?

Returns:
true if cancel, false otherwise

connect

public void connect()
             throws java.io.IOException,
                    FTPException
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:
connect in interface FTPClientInterface
Overrides:
connect in class SCPClient
Throws:
java.io.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

public java.lang.String getDetectedRemoteEOL()
Get the EOL detected by the client

Returns:

connected

public boolean connected()
Is the client currently connected?

Specified by:
connected in interface FTPClientInterface
Overrides:
connected in class SCPClient
Returns:
true if connected, false otherwise

setProgressMonitor

public void setProgressMonitor(FTPProgressMonitor monitor,
                               long interval)
Description copied from interface: FTPClientInterface
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.

Specified by:
setProgressMonitor in interface FTPClientInterface
Parameters:
monitor - the monitor object
interval - bytes transferred in between callbacks

setProgressMonitor

public void setProgressMonitor(FTPProgressMonitor monitor)
Description copied from interface: FTPClientInterface
Set a progress monitor for callbacks. Uses default callback interval

Specified by:
setProgressMonitor in interface FTPClientInterface
Parameters:
monitor - the monitor object

getMonitorInterval

public long getMonitorInterval()
Description copied from interface: FTPClientInterface
Get the bytes transferred between each callback on the progress monitor

Specified by:
getMonitorInterval in interface FTPClientInterface
Returns:
long bytes to be transferred before a callback

setMonitorInterval

public void setMonitorInterval(long interval)
Set the progress monitor interval for notifications

Parameters:
interval - notification interval

getProgressMonitor

public FTPProgressMonitor getProgressMonitor()
Get the reference to the progress monitor

Returns:
progress monitor

size

public long size(java.lang.String remoteFile)
          throws java.io.IOException,
                 FTPException
Description copied from interface: FTPClientInterface
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)

Specified by:
size in interface FTPClientInterface
Parameters:
remoteFile - name or path of remote file in current directory
Returns:
size of file in bytes
Throws:
java.io.IOException
FTPException

put

public java.lang.String put(java.lang.String localPath,
                            java.lang.String remoteFile)
                     throws java.io.IOException,
                            FTPException
Description copied from class: SCPClient
Upload a file.

Specified by:
put in interface FTPClientInterface
Overrides:
put in class SCPClient
Parameters:
localPath - path of local file to be uploaded
remoteFile - 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:
java.io.IOException
FTPException

put

public java.lang.String put(java.lang.String localPath,
                            java.lang.String remoteFile,
                            boolean append)
                     throws java.io.IOException,
                            FTPException
Description copied from interface: FTPClientInterface
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.

Specified by:
put in interface FTPClientInterface
Parameters:
localPath - path of the local file
remoteFile - name of remote file in current directory, or null if a unique filename is to be generated by the server
append - 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:
java.io.IOException
FTPException

put

public java.lang.String put(java.io.InputStream srcStream,
                            java.lang.String remoteFile)
                     throws java.io.IOException,
                            FTPException
Description copied from interface: FTPClientInterface
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.

Specified by:
put in interface FTPClientInterface
Parameters:
srcStream - input stream of data to put
remoteFile - 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:
java.io.IOException
FTPException

put

public java.lang.String put(java.io.InputStream srcStream,
                            java.lang.String remoteFile,
                            boolean append)
                     throws java.io.IOException,
                            FTPException
Description copied from interface: FTPClientInterface
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.

Specified by:
put in interface FTPClientInterface
Parameters:
srcStream - input stream of data to put
remoteFile - name of remote file in current directory, or null if a unique filename is to be generated by the server
append - 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:
java.io.IOException
FTPException

put

public java.lang.String put(byte[] bytes,
                            java.lang.String remoteFile)
                     throws java.io.IOException,
                            FTPException
Description copied from interface: FTPClientInterface
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.

Specified by:
put in interface FTPClientInterface
Parameters:
bytes - array of bytes
remoteFile - 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:
java.io.IOException
FTPException

put

public java.lang.String put(byte[] bytes,
                            java.lang.String remoteFile,
                            boolean append)
                     throws java.io.IOException,
                            FTPException
Description copied from interface: FTPClientInterface
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.

Specified by:
put in interface FTPClientInterface
Parameters:
bytes - array of bytes
remoteFile - name of remote file in current directory, or null if a unique filename is to be generated by the server
append - 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:
java.io.IOException
FTPException

get

public void get(java.lang.String localPath,
                java.lang.String remoteFile)
         throws java.io.IOException,
                FTPException
Description copied from class: SCPClient
Download a file

Specified by:
get in interface FTPClientInterface
Overrides:
get in class SCPClient
Parameters:
localPath - path of local file to download to
remoteFile - path of remote file
Throws:
java.io.IOException
FTPException

get

public void get(java.io.OutputStream destStream,
                java.lang.String remoteFile)
         throws java.io.IOException,
                FTPException
Description copied from interface: FTPClientInterface
Get data from the FTP server. Uses the currently set transfer mode.

Specified by:
get in interface FTPClientInterface
Parameters:
destStream - data stream to write data to
remoteFile - name of remote file in current directory
Throws:
java.io.IOException
FTPException

get

public byte[] get(java.lang.String remoteFile)
           throws java.io.IOException,
                  FTPException
Description copied from interface: FTPClientInterface
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.

Specified by:
get in interface FTPClientInterface
Parameters:
remoteFile - name of remote file in current directory
Throws:
java.io.IOException
FTPException

dirDetails

public FTPFile[] dirDetails(java.lang.String dirname)
                     throws java.io.IOException,
                            FTPException,
                            java.text.ParseException
Description copied from interface: FTPClientInterface
List a directory's contents as an array of FTPFile objects. 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:
dirDetails in interface FTPClientInterface
Parameters:
dirname - name of directory (some servers permit a filemask)
Returns:
an array of FTPFile objects
Throws:
java.io.IOException
FTPException
java.text.ParseException

dir

public java.lang.String[] dir()
                       throws java.io.IOException,
                              FTPException
Description copied from interface: FTPClientInterface
List current directory's contents as an array of strings of filenames.

Specified by:
dir in interface FTPClientInterface
Returns:
an array of current directory listing strings
Throws:
java.io.IOException
FTPException

dir

public java.lang.String[] dir(java.lang.String dirname)
                       throws java.io.IOException,
                              FTPException
Description copied from interface: FTPClientInterface
List a directory's contents as an array of strings of filenames.

Specified by:
dir in interface FTPClientInterface
Parameters:
dirname - name of directory OR filemask
Returns:
an array of directory listing strings
Throws:
java.io.IOException
FTPException

dir

public java.lang.String[] dir(java.lang.String dirname,
                              boolean full)
                       throws java.io.IOException,
                              FTPException
Description copied from interface: FTPClientInterface
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

Specified by:
dir in interface FTPClientInterface
Parameters:
dirname - name of directory OR filemask
full - true if detailed listing required false otherwise
Returns:
an array of directory listing strings
Throws:
java.io.IOException
FTPException

delete

public void delete(java.lang.String remoteFile)
            throws java.io.IOException,
                   FTPException
Description copied from interface: FTPClientInterface
Delete the specified remote file

Specified by:
delete in interface FTPClientInterface
Parameters:
remoteFile - name of remote file to delete
Throws:
java.io.IOException
FTPException

rename

public void rename(java.lang.String from,
                   java.lang.String to)
            throws java.io.IOException,
                   FTPException
Description copied from interface: FTPClientInterface
Rename a file or directory

Specified by:
rename in interface FTPClientInterface
Parameters:
from - name of file or directory to rename
to - intended name
Throws:
java.io.IOException
FTPException

exists

public boolean exists(java.lang.String remoteFile)
               throws java.io.IOException,
                      FTPException
Description copied from interface: FTPClientInterface
Does the named file exist in the current server directory?

Specified by:
exists in interface FTPClientInterface
Parameters:
remoteFile - name of remote file
Returns:
true if exists, false otherwise
Throws:
java.io.IOException
FTPException

rmdir

public void rmdir(java.lang.String dir)
           throws java.io.IOException,
                  FTPException
Description copied from interface: FTPClientInterface
Delete the specified remote working directory

Specified by:
rmdir in interface FTPClientInterface
Parameters:
dir - name of remote directory to delete
Throws:
java.io.IOException
FTPException

mkdir

public void mkdir(java.lang.String dir)
           throws java.io.IOException,
                  FTPException
Description copied from interface: FTPClientInterface
Create the specified remote working directory

Specified by:
mkdir in interface FTPClientInterface
Parameters:
dir - name of remote directory to create
Throws:
java.io.IOException
FTPException

changeMode

public void changeMode(int permissions,
                       java.lang.String path)
                throws java.io.IOException,
                       FTPException
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:
java.io.IOException - if an IO error occurs or the file if not found
FTPException

changeGroup

public void changeGroup(int gid,
                        java.lang.String path)
                 throws java.io.IOException,
                        FTPException
Sets the group ID for the file or directory.

Parameters:
gid - the numeric group id for the new group
path - the path to the remote file/directory
Throws:
java.io.IOException - if an IO error occurs or the file does not exist
FTPException

changeOwner

public void changeOwner(int uid,
                        java.lang.String path)
                 throws java.io.IOException,
                        FTPException
Sets the user ID to owner for the file or directory.

Parameters:
uid - numeric user id of the new owner
path - the path to the remote file/directory
Throws:
java.io.IOException - if an IO error occurs or the file does not exist
FTPException

setUmask

public void setUmask(java.lang.String umask)
              throws FTPException
Sets the umask used to write permissions

Parameters:
umask - umask as 4 digit octal, e.g. 0022
Throws:
FTPException

getUmask

public java.lang.String getUmask()
                          throws FTPException
Get the current umask

Returns:
current umask as octal string
Throws:
FTPException

chdir

public void chdir(java.lang.String dir)
           throws java.io.IOException,
                  FTPException
Description copied from interface: FTPClientInterface
Change the remote working directory to that supplied

Specified by:
chdir in interface FTPClientInterface
Parameters:
dir - name of remote directory to change to
Throws:
java.io.IOException
FTPException

cdup

public void cdup()
          throws java.io.IOException,
                 FTPException
Description copied from interface: FTPClientInterface
Change the remote working directory to the parent directory

Specified by:
cdup in interface FTPClientInterface
Throws:
java.io.IOException
FTPException

modtime

public java.util.Date modtime(java.lang.String remoteFile)
                       throws java.io.IOException,
                              FTPException
Description copied from interface: FTPClientInterface
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.

Specified by:
modtime in interface FTPClientInterface
Parameters:
remoteFile - name of remote file
Throws:
java.io.IOException
FTPException

setModTime

public void setModTime(java.lang.String path,
                       java.util.Date modTime)
                throws java.io.IOException,