Class SftpClient

    • Constructor Summary

      Constructors 
      Constructor Description
      SftpClient​(java.lang.String host)
      Constructor assuming the default SSH port.
      SftpClient​(java.lang.String host, int port, int timeout)
      Constructor.
      SftpClient​(java.lang.String host, int port, int timeout, java.io.File knownHostsFile, ConfigBuilder configBuilder)
      Constructor.
      SftpClient​(java.net.InetAddress addr)
      Constructor assuming the default SSH port.
      SftpClient​(java.net.InetAddress addr, int port, int timeout)
      Constructor.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void chdir​(java.lang.String dir)
      Change the remote working directory to that supplied
      void connect​(java.lang.String user, byte[] prvKey, byte[] prvKeyPwd)
      Connect and login into an account on the SFTP server.
      void connect​(java.lang.String user, java.lang.String password)
      Connect and login into an account on the FTP server.
      void delete​(java.lang.String remoteFile)
      Delete the specified remote file
      java.lang.String[] dir​(java.lang.String dirname, boolean full)
      List a directory's contents as an array of strings.
      java.lang.String[] dir​(java.lang.String directory, java.io.FileFilter filter)
      List a directory's contents
      void disconnect()
      Quit the FTP session
      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.
      long getKeepAliveTimeout()
      Get the time to wait between sending control connection keepalive messages.
      boolean isConnected()
      Check if this client is still connected to its target Any errors return a false This is used to check cached connections are still working
      boolean isDirectory​(java.lang.String path)  
      long lastModified​(java.lang.String remoteFile)
      Return the last modified time for the given path.
      java.util.Date lastModifiedDate​(java.lang.String remoteFile)
      Return the last modified date for the given path.
      void mkdir​(java.lang.String dir)
      Create the specified remote working directory
      void put​(java.io.InputStream srcStream, java.lang.String remoteFile, boolean append)
      Put a stream of data onto the FTP server.
      void rename​(java.lang.String from, java.lang.String to)
      Rename a file or directory
      void rmdir​(java.lang.String dir)
      Delete the specified remote working directory
      void setKeepAliveTimeout​(long seconds)
      Set the time to wait between sending control connection keepalive messages when processing file upload or download.
      void setKnownHosts​(java.lang.String knownHostsFilename)  
      SftpClient withAdditionalDebug​(boolean onoff)  
      SftpClient withKeepAliveTimeout​(long seconds)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • NO_KERBEROS_AUTH

        public static final java.lang.String NO_KERBEROS_AUTH
        See Also:
        Constant Field Values
      • SSH_PREFERRED_AUTHENTICATIONS

        public static final java.lang.String SSH_PREFERRED_AUTHENTICATIONS
        See Also:
        Constant Field Values
    • Constructor Detail

      • SftpClient

        public SftpClient​(java.lang.String host)
                   throws SftpException
        Constructor assuming the default SSH port.
        Parameters:
        host - the remote ssh host.
        Throws:
        SftpException
      • SftpClient

        public SftpClient​(java.net.InetAddress addr)
                   throws SftpException
        Constructor assuming the default SSH port.
        Parameters:
        addr - the remote ssh host.
        Throws:
        SftpException
      • SftpClient

        public SftpClient​(java.net.InetAddress addr,
                          int port,
                          int timeout)
                   throws SftpException
        Constructor.
        Parameters:
        addr - the remote ssh host.
        port - the ssh port.
        timeout - the timeout;
        Throws:
        SftpException
      • SftpClient

        public SftpClient​(java.lang.String host,
                          int port,
                          int timeout)
                   throws SftpException
        Constructor.
        Parameters:
        host - the host
        port - the port
        timeout - the timeout;
        Throws:
        SftpException
      • SftpClient

        public SftpClient​(java.lang.String host,
                          int port,
                          int timeout,
                          java.io.File knownHostsFile,
                          ConfigBuilder configBuilder)
                   throws SftpException
        Constructor.
        Parameters:
        host - the host
        port - the port
        timeout - the timeout;
        configBuilder - any required behaviour for this client;
        Throws:
        SftpException
    • Method Detail

      • connect

        public void connect​(java.lang.String user,
                            byte[] prvKey,
                            byte[] prvKeyPwd)
                     throws FileTransferException
        Connect and login into an account on the SFTP server. This completes the entire login process
        Parameters:
        user - user name
        prvKey - private key as part of public/private key pair
        prvKeyPwd - the password for accessing the private key.
        Throws:
        FileTransferException - if an FTP specific exception occurs
      • dir

        public java.lang.String[] dir​(java.lang.String directory,
                                      java.io.FileFilter filter)
                               throws FileTransferException,
                                      java.io.IOException
        Description copied from interface: FileTransferClient
        List a directory's contents

        Note that although we use a standard FileFilter interface here operating on File; it actually uses RemoteFile instead which overrides information that can be obtained from the remote server. Other standard File operations will not be supported, and may ultimately cause a runtime exception.

        Parameters:
        directory - the directory to list.
        filter - the filefilter mask to use
        Returns:
        an array of strings containing the listing
        Throws:
        FileTransferException - on FTP Specific exception error.
        java.io.IOException - on comms error.
      • dir

        public java.lang.String[] dir​(java.lang.String dirname,
                                      boolean full)
                               throws java.io.IOException,
                                      FileTransferException
        Description copied from interface: FileTransferClient
        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. The special files "." and ".." are ignored.

        Parameters:
        dirname - name of directory (not a file mask)
        full - true if detailed listing required false otherwise
        Returns:
        an array of directory listing strings
        Throws:
        FileTransferException - if an FTP specific exception occurs
        java.io.IOException - if a comms error occurs
        See Also:
        FileTransferClient.dir(java.lang.String, boolean)
      • rename

        public void rename​(java.lang.String from,
                           java.lang.String to)
                    throws java.io.IOException,
                           FileTransferException
        Description copied from interface: FileTransferClient
        Rename a file or directory
        Parameters:
        from - name of file or directory to rename
        to - intended name
        Throws:
        FileTransferException - if an FTP specific exception occurs
        java.io.IOException - if a comms error occurs
      • rmdir

        public void rmdir​(java.lang.String dir)
                   throws java.io.IOException,
                          FileTransferException
        Description copied from interface: FileTransferClient
        Delete the specified remote working directory
        Parameters:
        dir - name of remote directory to delete
        Throws:
        FileTransferException - if an FTP specific exception occurs
        java.io.IOException - if a comms error occurs
      • mkdir

        public void mkdir​(java.lang.String dir)
                   throws java.io.IOException,
                          FileTransferException
        Description copied from interface: FileTransferClient
        Create the specified remote working directory
        Parameters:
        dir - name of remote directory to create
        Throws:
        FileTransferException - if an FTP specific exception occurs
        java.io.IOException - if a comms error occurs
      • chdir

        public void chdir​(java.lang.String dir)
                   throws java.io.IOException,
                          FileTransferException
        Description copied from interface: FileTransferClient
        Change the remote working directory to that supplied
        Parameters:
        dir - name of remote directory to change to
        Throws:
        FileTransferException - if an FTP specific exception occurs
        java.io.IOException - if a comms error occurs
      • isDirectory

        public boolean isDirectory​(java.lang.String path)
                            throws java.io.IOException
        Throws:
        java.io.IOException
      • getKeepAliveTimeout

        public long getKeepAliveTimeout()
                                 throws FtpException
        Description copied from interface: FileTransferClient
        Get the time to wait between sending control connection keepalive messages.
        Returns:
        time in seconds
        Throws:
        FtpException
      • setKeepAliveTimeout

        public void setKeepAliveTimeout​(long seconds)
                                 throws FtpException
        Description copied from interface: FileTransferClient
        Set the time to wait between sending control connection keepalive messages when processing file upload or download.
        Parameters:
        seconds - time in seconds
        Throws:
        FtpException
      • withAdditionalDebug

        public SftpClient withAdditionalDebug​(boolean onoff)
      • isConnected

        public boolean isConnected()
        Description copied from interface: FileTransferClient
        Check if this client is still connected to its target Any errors return a false This is used to check cached connections are still working
        Returns:
        true = connected, false = not connected or some error