Class SSHFTPClient

java.lang.Object
com.enterprisedt.net.ftp.ssh.SCPClient
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$
Author:
Hans Andersen
  • Field Details

  • 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

      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
    • 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:
      getFileLockingEnabled in interface FTPClientInterface
      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:
      setFileLockingEnabled in interface FTPClientInterface
      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:
      setMaxTransferRate in interface ProFTPClientInterface
      Parameters:
      thresholdBytesPerSecond - maximum bytes per second to transfer
    • getMaxTransferRate

      public int getMaxTransferRate()
      Get the maximum bandwidth for transfers
      Specified by:
      getMaxTransferRate in interface ProFTPClientInterface
      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

      public void setServerResponseTimeout(long serverResponseTimeout) throws FTPException
      Deprecated.
      Set the server response timeout. Must be called before connecting.
      Parameters:
      serverResponseTimeout - server response timeout in milliseconds
      Throws:
      FTPException
    • setControlEncoding

      public void setControlEncoding(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:
    • getHostPublicKey

      public static SSHFTPPublicKey getHostPublicKey(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(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 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:
      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:
      the default 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. 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

      public void setRemoteEOL(String remoteEOL)
      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

      public 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 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(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.
    • resumeNextDownload

      public void resumeNextDownload(long offset) throws FTPException
      Resumes the next download from the offset point, which must be smaller than the length of the file to be downloaded.
      Specified by:
      resumeNextDownload in interface FTPClientInterface
      Parameters:
      offset - offset bytes are skipped before downloading the file.
      Throws:
      FTPException
    • 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 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:
      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 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:
      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 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
      Specified by:
      setMonitorInterval in interface ProFTPClientInterface
      Parameters:
      interval - notification interval
    • getProgressMonitor

      public FTPProgressMonitor getProgressMonitor()
      Get the reference to the progress monitor
      Returns:
      progress monitor
    • getProgressMonitorEx

      public FTPProgressMonitorEx getProgressMonitorEx()
      Get reference to the transfer listener
      Specified by:
      getProgressMonitorEx in interface ProFTPClientInterface
      Returns:
      FTPProgressMonitorEx
    • setProgressMonitorEx

      public void setProgressMonitorEx(FTPProgressMonitorEx monitorEx)
      Set reference to the transfer listener
      Specified by:
      setProgressMonitorEx in interface ProFTPClientInterface
      Parameters:
      monitorEx - transfer listener
    • size

      public long size(String remoteFile) throws 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:
      IOException
      FTPException
    • put

      public String put(String localPath, String remoteFile) throws 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:
      IOException
      FTPException
    • put

      public String put(String localPath, String remoteFile, boolean append) throws 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:
      IOException
      FTPException
    • put

      public String put(InputStream srcStream, String remoteFile) throws 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:
      IOException
      FTPException
    • put

      public String put(InputStream srcStream, String remoteFile, boolean append) throws 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:
      IOException
      FTPException
    • put

      public String put(byte[] bytes, String remoteFile) throws 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:
      IOException
      FTPException
    • put

      public String put(byte[] bytes, String remoteFile, boolean append) throws 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:
      IOException
      FTPException
    • get

      public void get(String localPath, String remoteFile) throws 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:
      IOException
      FTPException
    • get

      public void get(OutputStream destStream, String remoteFile) throws 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:
      IOException
      FTPException
    • get

      public byte[] get(String remoteFile) throws 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:
      IOException
      FTPException
    • fileDetails

      public FTPFile fileDetails(String name) throws IOException, FTPException
      Get details about the named file
      Parameters:
      name - name of a file
      Returns:
      if it exists, an FTPFile object
      Throws:
      IOException
      FTPException
    • dirDetails

      public void dirDetails(String dirname, DirectoryListCallback lister) throws IOException, FTPException, ParseException
      Description copied from interface: FTPClientInterface
      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.
      Specified by:
      dirDetails in interface FTPClientInterface
      Parameters:
      dirname - name of directory (some servers permit a filemask)
      lister - callback to be notified of errors
      Throws:
      IOException
      FTPException
      ParseException
    • dirDetails

      public FTPFile[] dirDetails(String dirname) throws IOException, FTPException, ParseException
      Description copied from interface: FTPClientInterface
      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).
      Specified by:
      dirDetails in interface FTPClientInterface
      Parameters:
      dirname - name of directory (some servers permit a filemask)
      Returns:
      an array of FTPFile objects
      Throws:
      IOException
      FTPException
      ParseException
    • dir

      public String[] dir() throws IOException, FTPException
      Description copied from interface: FTPClientInterface
      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.
      Specified by:
      dir in interface FTPClientInterface
      Returns:
      an array of current directory listing strings
      Throws:
      IOException
      FTPException
    • dir

      public String[] dir(String dirname) throws IOException, FTPException
      Description copied from interface: FTPClientInterface
      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.
      Specified by:
      dir in interface FTPClientInterface
      Parameters:
      dirname - name of directory OR filemask
      Returns:
      an array of directory listing strings
      Throws:
      IOException
      FTPException
    • dir

      public String[] dir(String dirname, boolean full) throws 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. 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:
      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:
      IOException
      FTPException
    • delete

      public void delete(String remoteFile) throws 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:
      IOException
      FTPException
    • rename

      public void rename(String from, String to) throws 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:
      IOException
      FTPException
    • exists

      public boolean exists(String remoteFile) throws 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:
      IOException
      FTPException
    • rmdir

      public void rmdir(String dir) throws 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:
      IOException
      FTPException
    • mkdir

      public void mkdir(String dir) throws 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:
      IOException
      FTPException
    • changeMode

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

      public void changeMode(String permissions, String path) throws 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 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 string
      path - the path to the file/directory on the remote server
      Throws:
      IOException - if an IO error occurs or the file if not found
      FTPException
    • changeGroup

      public void changeGroup(int gid, String path) throws 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:
      IOException - if an IO error occurs or the file does not exist
      FTPException
    • changeOwner

      public void changeOwner(int uid, String path) throws 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:
      IOException - if an IO error occurs or the file does not exist
      FTPException
    • setUmask

      public void setUmask(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 String getUmask() throws FTPException
      Get the current umask
      Returns:
      current umask as octal string
      Throws:
      FTPException
    • chdir

      public void chdir(String dir) throws 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:
      IOException
      FTPException
    • cdup

      public void cdup() throws IOException, FTPException
      Description copied from interface: FTPClientInterface
      Change the remote working directory to the parent directory
      Specified by:
      cdup in interface FTPClientInterface
      Throws:
      IOException
      FTPException
    • modtime

      public Date modtime(String remoteFile) throws 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:
      IOException
      FTPException
    • setModTime

      public void setModTime(String path, Date modTime) throws IOException, FTPException
      Set the last modified time for the supplied file
      Specified by:
      setModTime in interface FTPClientInterface
      Parameters:
      path - the path to the file/directory on the remote server
      modTime - the time stamp (UTC) of when it was last modified
      Throws:
      IOException
      FTPException
    • pwd

      public String pwd() throws IOException, FTPException
      Description copied from interface: FTPClientInterface
      Get the current remote working directory
      Specified by:
      pwd in interface FTPClientInterface
      Returns:
      the current working directory
      Throws:
      IOException
      FTPException
    • mdelete

      public void mdelete(String wildcard) throws IOException, FTPException, ParseException
      Description copied from interface: ProFTPClientInterface
      Deletes all files matching the wildcard in the current remote directory only
      Specified by:
      mdelete in interface ProFTPClientInterface
      Parameters:
      wildcard -
      Throws:
      IOException
      FTPException
      ParseException
    • mdelete

      public void mdelete(FileFilter filter) throws IOException, FTPException, ParseException
      Description copied from interface: ProFTPClientInterface
      Deletes all files matching the filter in the current remote directory only
      Specified by:
      mdelete in interface ProFTPClientInterface
      Parameters:
      filter - file filter
      Throws:
      IOException
      FTPException
      ParseException
    • mdelete

      public void mdelete(String remoteDir, String wildcard, boolean recurse) throws IOException, FTPException, ParseException
      Description copied from interface: ProFTPClientInterface
      Delete 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:
      mdelete in interface ProFTPClientInterface
      Parameters:
      remoteDir - name of remote directory
      wildcard - filename wildcard
      recurse - if true, recurse through subdirectories
      Throws:
      IOException
      FTPException
      ParseException
    • mdelete

      public void mdelete(String remoteDir, FileFilter filter, boolean recurse) throws IOException, FTPException, ParseException
      Description copied from interface: ProFTPClientInterface
      Delete 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:
      mdelete in interface ProFTPClientInterface
      Parameters:
      remoteDir - name of remote directory
      filter - filename filter
      recurse - if true, recurse through subdirectories
      Throws:
      IOException
      FTPException
      ParseException
    • rmdir

      public void rmdir(String remoteDir, boolean recurse) throws IOException, FTPException, ParseException
      Description copied from interface: ProFTPClientInterface
      Delete 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:
      rmdir in interface ProFTPClientInterface
      Parameters:
      remoteDir - name of remote directory
      recurse - if true, recurse through subdirectories
      Throws:
      IOException
      FTPException
      ParseException
    • mput

      public void mput(String localDir, String wildcard) throws IOException, FTPException
      Description copied from interface: ProFTPClientInterface
      Put all files matching the wildcard in the supplied local directory only into the current remote directory
      Specified by:
      mput in interface ProFTPClientInterface
      Parameters:
      localDir - local directory to get files from
      wildcard - filename wildcard
      Throws:
      IOException
      FTPException
    • mput

      public void mput(String localDir, FileFilter filter) throws IOException, FTPException
      Description copied from interface: ProFTPClientInterface
      Put all files matching the wildcard in the supplied local directory only into the current remote directory
      Specified by:
      mput in interface ProFTPClientInterface
      Parameters:
      localDir - local directory to get files from
      filter - filename filter
      Throws:
      IOException
      FTPException
    • mput

      public void mput(String localDir, String remoteDir, String wildcard, boolean recurse) throws FTPException, IOException
      Description copied from interface: ProFTPClientInterface
      Puts 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:
      mput in interface ProFTPClientInterface
      Parameters:
      localDir - name of local directory
      remoteDir - name of remote directory
      wildcard - filename wildcard
      recurse - if true recurse into subdirectories
      Throws:
      FTPException
      IOException
    • mput

      public void mput(String localDir, String remoteDir, FileFilter filter, boolean recurse) throws FTPException, IOException
      Description copied from interface: ProFTPClientInterface
      Puts 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:
      mput in interface ProFTPClientInterface
      Parameters:
      localDir - name of local directory
      remoteDir - name of remote directory
      filter - filename filter
      recurse - if true recurse into subdirectories
      Throws:
      FTPException
      IOException
    • mget

      public void mget(String localDir, String wildcard) throws IOException, FTPException, ParseException
      Description copied from interface: ProFTPClientInterface
      Get all files matching the filter in the current remote directory only into the supplied local directory
      Specified by:
      mget in interface ProFTPClientInterface
      Parameters:
      localDir - local directory to get files from
      wildcard - filename wildcard
      Throws:
      IOException
      FTPException
      ParseException
    • mget

      public void mget(String localDir, FileFilter filter) throws IOException, FTPException, ParseException
      Description copied from interface: ProFTPClientInterface
      Get all files matching the filter in the current remote directory only into the supplied local directory
      Specified by:
      mget in interface ProFTPClientInterface
      Parameters:
      localDir - local directory to get files from
      filter - filename filter
      Throws:
      IOException
      FTPException
      ParseException
    • mget

      public void mget(String localDir, String remoteDir, String wildcard, boolean recurse) throws FTPException, IOException, ParseException
      Description copied from interface: ProFTPClientInterface
      Gets 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:
      mget in interface ProFTPClientInterface
      Parameters:
      localDir - name of local directory we are transferring into
      remoteDir - name of remote directory
      wildcard - filename wildcard
      recurse - if true recurse into subdirectories
      Throws:
      FTPException
      IOException
      ParseException
    • mget

      public void mget(String localDir, String remoteDir, FileFilter filter, boolean recurse) throws FTPException, IOException, ParseException
      Description copied from interface: ProFTPClientInterface
      Gets 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:
      mget in interface ProFTPClientInterface
      Parameters:
      localDir - name of local directory we are transferring into
      remoteDir - name of remote directory
      filter - filename filter
      recurse - if true recurse into subdirectories
      Throws:
      FTPException
      IOException
      ParseException
    • getCountBeforeSleep

      public int getCountBeforeSleep()
      Description copied from interface: ProFTPClientInterface
      Get the number of transfers set before sleeping
      Specified by:
      getCountBeforeSleep in interface ProFTPClientInterface
      Returns:
      integer
    • setCountBeforeSleep

      public void setCountBeforeSleep(int countBeforeSleep)
      Description copied from interface: ProFTPClientInterface
      Set the number of transfers required before sleeping
      Specified by:
      setCountBeforeSleep in interface ProFTPClientInterface
      Parameters:
      countBeforeSleep - maximum transfer count
    • isSleepEnabled

      public boolean isSleepEnabled()
      Description copied from interface: ProFTPClientInterface
      Is sleeping enabled?
      Specified by:
      isSleepEnabled in interface ProFTPClientInterface
      Returns:
      true if enabled
    • setSleepEnabled

      public void setSleepEnabled(boolean sleepEnabled)
      Description copied from interface: ProFTPClientInterface
      Set sleeping enabled to be on or off
      Specified by:
      setSleepEnabled in interface ProFTPClientInterface
      Parameters:
      sleepEnabled - if true, sleeping is enabled, otherwise it is switched off
    • getSleepTime

      public int getSleepTime()
      Description copied from interface: ProFTPClientInterface
      Get the number of seconds spent asleep
      Specified by:
      getSleepTime in interface ProFTPClientInterface
      Returns:
      integer
    • setSleepTime

      public void setSleepTime(int sleepTime)
      Description copied from interface: ProFTPClientInterface
      Set the time spent asleep
      Specified by:
      setSleepTime in interface ProFTPClientInterface
      Parameters:
      sleepTime - sleep time in seconds
    • keepAlive

      public void keepAlive() throws IOException, FTPException
      Tries to keep the current connection alive by sending an innocuous command to signal that the client is still active
      Specified by:
      keepAlive in interface FTPClientInterface
      Throws:
      IOException
      FTPException
    • quit

      public void quit() throws IOException, FTPException
      Description copied from interface: FTPClientInterface
      Quit the FTP session
      Specified by:
      quit in interface FTPClientInterface
      Overrides:
      quit in class SCPClient
      Throws:
      IOException
      FTPException
    • quitImmediately

      public void quitImmediately() throws IOException, FTPException
      Description copied from interface: FTPClientInterface
      Quit the FTP session immediately. If a transfer is underway it will be terminated.
      Specified by:
      quitImmediately in interface FTPClientInterface
      Overrides:
      quitImmediately in class SCPClient
      Throws:
      IOException
      FTPException
    • toString

      public String toString()
      String representation
      Overrides:
      toString in class SCPClient