Class SftpClient

java.lang.Object
com.sshtools.client.sftp.SftpClient
All Implemented Interfaces:
Closeable, AutoCloseable

public class SftpClient extends Object implements Closeable
An abstract task that implements an SFTP client.
  • Field Details

  • Constructor Details

    • SftpClient

      @Deprecated(since="3.1.0", forRemoval=true) public SftpClient(com.sshtools.common.ssh.SshConnection con) throws com.sshtools.common.ssh.SshException, com.sshtools.common.permissions.PermissionDeniedException, IOException
      Deprecated, for removal: This API element is subject to removal in a future version.
      Throws:
      com.sshtools.common.ssh.SshException
      com.sshtools.common.permissions.PermissionDeniedException
      IOException
    • SftpClient

      @Deprecated(since="3.1.0", forRemoval=true) public SftpClient(com.sshtools.common.ssh.SshConnection con, com.sshtools.common.files.AbstractFileFactory<?> fileFactory) throws com.sshtools.common.permissions.PermissionDeniedException, IOException, com.sshtools.common.ssh.SshException
      Deprecated, for removal: This API element is subject to removal in a future version.
      Throws:
      com.sshtools.common.permissions.PermissionDeniedException
      IOException
      com.sshtools.common.ssh.SshException
    • SftpClient

      @Deprecated(since="3.1.0", forRemoval=true) public SftpClient(SshClient ssh) throws com.sshtools.common.ssh.SshException, com.sshtools.common.permissions.PermissionDeniedException, IOException
      Deprecated, for removal: This API element is subject to removal in a future version.
      Throws:
      com.sshtools.common.ssh.SshException
      com.sshtools.common.permissions.PermissionDeniedException
      IOException
    • SftpClient

      @Deprecated(since="3.1.0", forRemoval=true) public SftpClient(SshClient ssh, com.sshtools.common.files.AbstractFileFactory<?> fileFactory) throws com.sshtools.common.ssh.SshException, com.sshtools.common.permissions.PermissionDeniedException, IOException
      Deprecated, for removal: This API element is subject to removal in a future version.
      Throws:
      com.sshtools.common.ssh.SshException
      com.sshtools.common.permissions.PermissionDeniedException
      IOException
  • Method Details

    • setBlockSize

      public void setBlockSize(int blocksize)
      Sets the block size used when transferring files, defaults to the optimized setting of 32768. You should not increase this value as the remote server may not be able to support higher blocksizes.
      Parameters:
      blocksize - block size
    • getSubsystemChannel

      public SftpChannel getSubsystemChannel()
      Returns the instance of the AbstractSftpChannel used by this class
      Returns:
      the AbstractSftpChannel instance
    • setTransferMode

      public void setTransferMode(int transferMode)

      Sets the transfer mode for current operations. The valid modes are:

      MODE_BINARY - Files are transferred in binary mode and no processing of text files is performed (default mode).

      MODE_TEXT - For servers supporting version 4+ of the SFTP protocol files are transferred in text mode. For earlier protocol versions the files are transfered in binary mode but the client performs processing of text; if files are written to the remote server the client ensures that the line endings conform to the remote EOL mode set using setRemoteEOL(int). For files retrieved from the server the EOL policy is based upon System policy as defined by the "line.seperator" system property.

      Parameters:
      transferMode - int
    • setStripEOL

      public void setStripEOL(boolean stripEOL)
      Strip all line endings in preference of the target system EOL setting.
      Parameters:
      stripEOL -
    • setRemoteEOL

      public void setRemoteEOL(int eolMode)

      When connected to servers running SFTP version 3 (or less) the remote EOL type needs to be explicitly set because there is no reliable way for the client to determine the type of EOL for text files. In versions 4+ a mechanism is provided and this setting is overridden.

      Valid values for this method are EOL_CRLF (default), EOL_CR, and EOL_LF.

      Parameters:
      eolMode - int
    • setLocalEOL

      public void setLocalEOL(int eolMode)

      Override the default local system EOL for text mode files.

      Valid values for this method are EOL_CRLF (default), EOL_CR, and EOL_LF.

      Parameters:
      eolMode - int
    • setForceRemoteEOL

      public void setForceRemoteEOL(boolean forceRemoteEOL)
      Override automatic detection of the remote EOL (any SFTP version). USE WITH CAUTION.
      Parameters:
      forceRemoteEOL -
    • getTransferMode

      public int getTransferMode()
      Returns:
      int
    • setBufferSize

      public void setBufferSize(int buffersize)
      Set the size of the buffer which is used to read from the local file system. This setting is used to optimize the writing of files by allowing for a large chunk of data to be read in one operation from a local file. The previous version simply read each block of data before sending however this decreased performance, this version now reads the file into a temporary buffer in order to reduce the number of local filesystem reads. This increases performance and so this setting should be set to the highest value possible. The default setting is negative which means the entire file will be read into a temporary buffer.
      Parameters:
      buffersize -
    • setMaxAsyncRequests

      public void setMaxAsyncRequests(int asyncRequests)
      Set the maximum number of asynchronous requests that are outstanding at any one time. This setting is used to optimize the reading and writing of files to/from the remote file system when using the get and put methods. The default for this setting is 100.
      Parameters:
      asyncRequests - aync requests
    • umask

      public int umask(int umask)
      Sets the umask used by this client.
       To give yourself full permissions for both files and directories and
       prevent the group and other users from having access:
       
         umask(077);
       
       This subtracts 077 from the system defaults for files and directories
       666 and 777. Giving a default access permissions for your files of
       600 (rw-------) and for directories of 700 (rwx------).
       
       To give all access permissions to the group and allow other users read
       and execute permission:
       
         umask(002);
       
       This subtracts 002 from the system defaults to give a default access permission
       for your files of 664 (rw-rw-r--) and for your directories of 775 (rwxrwxr-x).
       
       To give the group and other users all access except write access:
       
         umask(022);
       
       This subtracts 022 from the system defaults to give a default access permission
       for your files of 644 (rw-r--r--) and for your directories of 755 (rwxr-xr-x).
       
      Parameters:
      umask - umask
      Returns:
      the previous umask value
    • openFile

      public SftpHandle openFile(String fileName) throws com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException
      Throws:
      com.sshtools.common.sftp.SftpStatusException
      com.sshtools.common.ssh.SshException
    • openFile

      public SftpHandle openFile(String fileName, int flags) throws com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException
      Throws:
      com.sshtools.common.sftp.SftpStatusException
      com.sshtools.common.ssh.SshException
    • openDirectory

      public SftpHandle openDirectory(String path) throws com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException
      Throws:
      com.sshtools.common.sftp.SftpStatusException
      com.sshtools.common.ssh.SshException
    • readDirectory

      public List<SftpFile> readDirectory(SftpHandle dir) throws com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException
      Throws:
      com.sshtools.common.sftp.SftpStatusException
      com.sshtools.common.ssh.SshException
    • cd

      public void cd(String dir) throws com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException

      Changes the working directory on the remote server, or the user's default directory if null or any empty string is provided as the directory path. The user's default directory is typically their home directory but is dependent upon server implementation.

      Parameters:
      dir - the new working directory
      Throws:
      IOException - if an IO error occurs or the file does not exist
      com.sshtools.common.sftp.SftpStatusException
      com.sshtools.common.ssh.SshException
    • getDefaultDirectory

      public String getDefaultDirectory() throws com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException

      Get the default directory (or HOME directory)

      Returns:
      String
      Throws:
      com.sshtools.common.sftp.SftpStatusException
      com.sshtools.common.ssh.SshException
    • cdup

      public void cdup() throws com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException
      Change the working directory to the parent directory
      Throws:
      com.sshtools.common.sftp.SftpStatusException
      com.sshtools.common.ssh.SshException
    • addCustomRoot

      @Deprecated(since="3.1.0", forRemoval=true) public void addCustomRoot(String rootPath)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Add a custom file system root path such as "flash:"
      Parameters:
      rootPath -
      See Also:
      • SftpClientBuilder#withCustomRoots(String)
    • removeCustomRoot

      @Deprecated(since="3.1.0", forRemoval=true) public void removeCustomRoot(String rootPath)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Remove a custom file system root path such as "flash:"
      Parameters:
      rootPath -
      See Also:
      • SftpClientBuilder#withCustomRoots(String)
    • mkdir

      public void mkdir(String dir) throws com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException

      Creates a new directory on the remote server. This method will throw an exception if the directory already exists. To create directories and disregard any errors use the mkdirs method.

      Parameters:
      dir - the name of the new directory
      Throws:
      com.sshtools.common.sftp.SftpStatusException
      com.sshtools.common.ssh.SshException
    • mkdirs

      public void mkdirs(String dir) throws com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException

      Create a directory or set of directories. This method will not fail even if the directories exist. It is advisable to test whether the directory exists before attempting an operation by using stat to return the directories attributes.

      Parameters:
      dir - the path of directories to create.
      Throws:
      com.sshtools.common.sftp.SftpStatusException
      com.sshtools.common.ssh.SshException
    • isDirectoryOrLinkedDirectory

      public boolean isDirectoryOrLinkedDirectory(SftpFile file) throws com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException
      Determine whether the file object is pointing to a symbolic link that is pointing to a directory.
      Returns:
      boolean
      Throws:
      com.sshtools.common.sftp.SftpStatusException
      com.sshtools.common.ssh.SshException
    • exists

      public boolean exists(String path) throws com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException
      Determine if a path exists.
      Returns:
      boolean
      Throws:
      com.sshtools.common.sftp.SftpStatusException
      com.sshtools.common.ssh.SshException
    • pwd

      public String pwd() throws com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException

      Returns the absolute path name of the current remote working directory.

      Returns:
      the absolute path of the remote working directory.
      Throws:
      com.sshtools.common.ssh.SshException
      com.sshtools.common.sftp.SftpStatusException
    • ls

      public SftpFile[] ls() throws com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException

      List the contents of the current remote working directory.

      Returns a list of SftpFile instances for the current working directory.

      Returns:
      a list of SftpFile for the current working directory
      Throws:
      com.sshtools.common.sftp.SftpStatusException
      com.sshtools.common.ssh.SshException
    • ls

      public SftpFile[] ls(String path) throws com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException

      List the contents remote directory.

      Returns a list of SftpFile instances for the remote directory.

      Parameters:
      path - the path on the remote server to list
      Returns:
      a list of SftpFile for the remote directory
      Throws:
      com.sshtools.common.sftp.SftpStatusException
      com.sshtools.common.ssh.SshException
    • ls

      public SftpFile[] ls(String filter, boolean regexFilter, int maximumFiles) throws com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException
      Throws:
      com.sshtools.common.sftp.SftpStatusException
      com.sshtools.common.ssh.SshException
    • ls

      public SftpFile[] ls(String path, String filter, boolean regexFilter, int maximumFiles) throws com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException
      Throws:
      com.sshtools.common.sftp.SftpStatusException
      com.sshtools.common.ssh.SshException
    • lsIterator

      public Iterator<SftpFile> lsIterator() throws com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException
      Return an iterator for the current working directory. This method improves memory usage by only getting paged contents of the directory.
      Returns:
      Throws:
      com.sshtools.common.sftp.SftpStatusException
      com.sshtools.common.ssh.SshException
    • lsIterator

      public Iterator<SftpFile> lsIterator(String path) throws com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException
      Return an iterator for the path provided. This method improves memory usage by only getting paged contents of the directory.
      Parameters:
      path -
      Returns:
      Throws:
      com.sshtools.common.sftp.SftpStatusException
      com.sshtools.common.ssh.SshException
    • lcd

      public void lcd(String path) throws com.sshtools.common.sftp.SftpStatusException, IOException, com.sshtools.common.permissions.PermissionDeniedException

      Changes the local working directory.

      Parameters:
      path - the path to the new working directory
      Throws:
      com.sshtools.common.sftp.SftpStatusException
      IOException
      com.sshtools.common.permissions.PermissionDeniedException
    • lpwd

      public String lpwd() throws IOException, com.sshtools.common.permissions.PermissionDeniedException

      Returns the absolute path to the local working directory.

      Returns:
      the absolute path of the local working directory.
      Throws:
      com.sshtools.common.permissions.PermissionDeniedException
      IOException
    • getCurrentWorkingDirectory

      public com.sshtools.common.files.AbstractFile getCurrentWorkingDirectory()
    • get

      public com.sshtools.common.sftp.SftpFileAttributes get(String path, FileTransferProgress progress) throws com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException, TransferCancelledException, IOException, com.sshtools.common.permissions.PermissionDeniedException

      Download the remote file to the local computer.

      Parameters:
      path - the path to the remote file
      progress -
      Returns:
      the downloaded file's attributes
      Throws:
      com.sshtools.common.sftp.SftpStatusException
      com.sshtools.common.ssh.SshException
      TransferCancelledException
      com.sshtools.common.permissions.PermissionDeniedException
      IOException
    • get

      public com.sshtools.common.sftp.SftpFileAttributes get(String path, FileTransferProgress progress, boolean resume) throws com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException, TransferCancelledException, IOException, com.sshtools.common.permissions.PermissionDeniedException

      Download the remote file to the local computer.

      Parameters:
      path - the path to the remote file
      progress -
      resume - attempt to resume a interrupted download
      Returns:
      the downloaded file's attributes
      Throws:
      com.sshtools.common.sftp.SftpStatusException
      com.sshtools.common.ssh.SshException
      TransferCancelledException
      com.sshtools.common.permissions.PermissionDeniedException
      IOException
    • get

      public com.sshtools.common.sftp.SftpFileAttributes get(String path, boolean resume) throws com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException, TransferCancelledException, IOException, com.sshtools.common.permissions.PermissionDeniedException

      Download the remote file to the local computer

      Parameters:
      path - the path to the remote file
      resume - attempt to resume an interrupted download
      Returns:
      the downloaded file's attributes
      Throws:
      com.sshtools.common.sftp.SftpStatusException
      com.sshtools.common.ssh.SshException
      TransferCancelledException
      com.sshtools.common.permissions.PermissionDeniedException
      IOException
    • get

      public com.sshtools.common.sftp.SftpFileAttributes get(String path) throws com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException, TransferCancelledException, IOException, com.sshtools.common.permissions.PermissionDeniedException

      Download the remote file to the local computer

      Parameters:
      path - the path to the remote file
      Returns:
      the downloaded file's attributes
      Throws:
      com.sshtools.common.sftp.SftpStatusException
      com.sshtools.common.ssh.SshException
      TransferCancelledException
      com.sshtools.common.permissions.PermissionDeniedException
      IOException
    • getSymbolicLinkTarget

      public String getSymbolicLinkTarget(String linkpath) throws com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException
      Get the target path of a symbolic link.
      Parameters:
      linkpath -
      Returns:
      String
      Throws:
      com.sshtools.common.ssh.SshException - if the remote SFTP version is < 3 an exception is thrown as this feature is not supported by previous versions of the protocol.
      com.sshtools.common.sftp.SftpStatusException
    • get

      public com.sshtools.common.sftp.SftpFileAttributes get(String remote, String local, FileTransferProgress progress) throws com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException, TransferCancelledException, IOException, com.sshtools.common.permissions.PermissionDeniedException

      Download the remote file to the local computer. If the paths provided are not absolute the current working directory is used.

      Parameters:
      remote - the path/name of the remote file
      local - the path/name to place the file on the local computer
      progress -
      Returns:
      the downloaded file's attributes
      Throws:
      com.sshtools.common.sftp.SftpStatusException
      com.sshtools.common.ssh.SshException
      TransferCancelledException
      com.sshtools.common.permissions.PermissionDeniedException
      IOException
    • get

      public com.sshtools.common.sftp.SftpFileAttributes get(String remote, String local, FileTransferProgress progress, boolean resume) throws com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException, TransferCancelledException, IOException, com.sshtools.common.permissions.PermissionDeniedException

      Download the remote file to the local computer. If the paths provided are not absolute the current working directory is used.

      Parameters:
      remote - the path/name of the remote file
      local - the path/name to place the file on the local computer
      progress -
      resume - attempt to resume an interrupted download
      Returns:
      the downloaded file's attributes
      Throws:
      com.sshtools.common.sftp.SftpStatusException
      com.sshtools.common.ssh.SshException
      TransferCancelledException
      com.sshtools.common.permissions.PermissionDeniedException
      IOException
    • getRemoteNewline

      public String getRemoteNewline() throws com.sshtools.common.sftp.SftpStatusException
      Throws:
      com.sshtools.common.sftp.SftpStatusException
    • getRemoteEOL

      public int getRemoteEOL() throws com.sshtools.common.sftp.SftpStatusException
      Throws:
      com.sshtools.common.sftp.SftpStatusException
    • getEOL

      public int getEOL(String line) throws com.sshtools.common.sftp.SftpStatusException
      Throws:
      com.sshtools.common.sftp.SftpStatusException
    • getEOL

      public int getEOL(byte[] nl) throws com.sshtools.common.sftp.SftpStatusException
      Throws:
      com.sshtools.common.sftp.SftpStatusException
    • get

      public com.sshtools.common.sftp.SftpFileAttributes get(String remote, String local, boolean resume) throws com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException, TransferCancelledException, IOException, com.sshtools.common.permissions.PermissionDeniedException
      Download the remote file into the local file.
      Parameters:
      remote -
      local -
      resume - attempt to resume an interrupted download
      Returns:
      the downloaded file's attributes
      Throws:
      com.sshtools.common.sftp.SftpStatusException
      com.sshtools.common.ssh.SshException
      TransferCancelledException
      com.sshtools.common.permissions.PermissionDeniedException
      IOException
    • get

      public com.sshtools.common.sftp.SftpFileAttributes get(String remote, String local) throws com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException, TransferCancelledException, IOException, com.sshtools.common.permissions.PermissionDeniedException
      Download the remote file into the local file.
      Parameters:
      remote -
      local -
      Returns:
      the downloaded file's attributes
      Throws:
      com.sshtools.common.sftp.SftpStatusException
      com.sshtools.common.ssh.SshException
      TransferCancelledException
      com.sshtools.common.permissions.PermissionDeniedException
      IOException
    • get

      public com.sshtools.common.sftp.SftpFileAttributes get(String remote, OutputStream local, FileTransferProgress progress) throws com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException, TransferCancelledException

      Download the remote file writing it to the specified OutputStream. The OutputStream is closed by this method even if the operation fails.

      Parameters:
      remote - the path/name of the remote file
      local - the OutputStream to write
      progress -
      Returns:
      the downloaded file's attributes
      Throws:
      com.sshtools.common.sftp.SftpStatusException
      com.sshtools.common.ssh.SshException
      TransferCancelledException
    • setRegularExpressionSyntax

      public void setRegularExpressionSyntax(int syntax)
      sets the type of regular expression matching to perform on gets and puts
      Parameters:
      syntax - , NoSyntax for no regular expression matching, GlobSyntax for GlobSyntax, Perl5Syntax for Perl5Syntax
    • matchRemoteFiles

      public SftpFile[] matchRemoteFiles(String remote) throws com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException
      Called by getFileMatches() to do regular expression pattern matching on the files in 'remote''s parent directory.
      Parameters:
      remote -
      Returns:
      SftpFile[]
      Throws:
      com.sshtools.common.sftp.SftpStatusException
      com.sshtools.common.ssh.SshException
    • get

      public com.sshtools.common.sftp.SftpFileAttributes get(String remote, OutputStream local, FileTransferProgress progress, long position) throws com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException, TransferCancelledException

      Download the remote file writing it to the specified OutputStream. The OutputStream is closed by this method even if the operation fails.

      Parameters:
      remote - the path/name of the remote file
      local - the OutputStream to write
      progress -
      position - the position within the file to start reading from
      Returns:
      the downloaded file's attributes
      Throws:
      com.sshtools.common.sftp.SftpStatusException
      com.sshtools.common.ssh.SshException
      TransferCancelledException
    • getInputStream

      public InputStream getInputStream(String remotefile, long position) throws com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException
      Create an InputStream for reading a remote file.
      Parameters:
      remotefile -
      position -
      Returns:
      InputStream
      Throws:
      com.sshtools.common.sftp.SftpStatusException
      com.sshtools.common.ssh.SshException
    • getInputStream

      public InputStream getInputStream(String remotefile) throws com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException
      Create an InputStream for reading a remote file.
      Parameters:
      remotefile -
      Returns:
      InputStream
      Throws:
      com.sshtools.common.sftp.SftpStatusException
      com.sshtools.common.ssh.SshException
    • get

      public com.sshtools.common.sftp.SftpFileAttributes get(String remote, OutputStream local, long position) throws com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException, TransferCancelledException
      Download the remote file into an OutputStream.
      Parameters:
      remote -
      local -
      position - the position from which to start reading the remote file
      Returns:
      the downloaded file's attributes
      Throws:
      com.sshtools.common.sftp.SftpStatusException
      com.sshtools.common.ssh.SshException
      TransferCancelledException
    • get

      public com.sshtools.common.sftp.SftpFileAttributes get(String remote, OutputStream local) throws com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException, TransferCancelledException
      Download the remote file into an OutputStream.
      Parameters:
      remote -
      local -
      Returns:
      the downloaded file's attributes
      Throws:
      com.sshtools.common.sftp.SftpStatusException
      com.sshtools.common.ssh.SshException
      TransferCancelledException
    • isClosed

      public boolean isClosed()

      Returns the state of the SFTP client. The client is closed if the underlying session channel is closed. Invoking the quit method of this object will close the underlying session channel.

      Returns:
      true if the client is still connected, otherwise false
    • put

      public void put(String local, FileTransferProgress progress, boolean resume) throws com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException, TransferCancelledException, IOException, com.sshtools.common.permissions.PermissionDeniedException

      Upload a file to the remote computer.

      Parameters:
      local - the path/name of the local file
      progress -
      Throws:
      com.sshtools.common.sftp.SftpStatusException
      com.sshtools.common.ssh.SshException
      TransferCancelledException
      com.sshtools.common.permissions.PermissionDeniedException
      IOException
    • put

      public void put(String local, FileTransferProgress progress) throws com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException, TransferCancelledException, IOException, com.sshtools.common.permissions.PermissionDeniedException

      Upload a file to the remote computer.

      Parameters:
      local - the path/name of the local file
      progress -
      Throws:
      com.sshtools.common.sftp.SftpStatusException
      com.sshtools.common.ssh.SshException
      TransferCancelledException
      com.sshtools.common.permissions.PermissionDeniedException
      IOException
    • put

      public void put(String local) throws com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException, TransferCancelledException, IOException, com.sshtools.common.permissions.PermissionDeniedException
      Upload a file to the remote computer
      Parameters:
      local -
      Throws:
      com.sshtools.common.sftp.SftpStatusException
      com.sshtools.common.ssh.SshException
      TransferCancelledException
      com.sshtools.common.permissions.PermissionDeniedException
      IOException
    • put

      public void put(String local, boolean resume) throws com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException, TransferCancelledException, IOException, com.sshtools.common.permissions.PermissionDeniedException
      Upload a file to the remote computer
      Parameters:
      local -
      resume - attempt to resume after an interrupted transfer
      Throws:
      com.sshtools.common.sftp.SftpStatusException
      com.sshtools.common.ssh.SshException
      TransferCancelledException
      com.sshtools.common.permissions.PermissionDeniedException
      IOException
    • put

      public void put(String local, String remote, FileTransferProgress progress) throws com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException, TransferCancelledException, IOException, com.sshtools.common.permissions.PermissionDeniedException

      Upload a file to the remote computer. If the paths provided are not absolute the current working directory is used.

      Parameters:
      local - the path/name of the local file
      remote - the path/name of the destination file
      progress -
      Throws:
      com.sshtools.common.sftp.SftpStatusException
      com.sshtools.common.ssh.SshException
      TransferCancelledException
      com.sshtools.common.permissions.PermissionDeniedException
      IOException
    • append

      public void append(InputStream in, String remote) throws com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException, TransferCancelledException
      Throws:
      com.sshtools.common.sftp.SftpStatusException
      com.sshtools.common.ssh.SshException
      TransferCancelledException
    • append

      @Deprecated public void append(InputStream in, String remote, FileTransferProgress progress) throws com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException, TransferCancelledException
      Deprecated.
      Throws:
      com.sshtools.common.sftp.SftpStatusException
      com.sshtools.common.ssh.SshException
      TransferCancelledException
    • append

      public void append(InputStream in, String remote, FileTransferProgress progress, long length) throws com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException, TransferCancelledException
      Throws:
      com.sshtools.common.sftp.SftpStatusException
      com.sshtools.common.ssh.SshException
      TransferCancelledException
    • put

      public void put(String local, String remote, FileTransferProgress progress, boolean resume) throws com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException, TransferCancelledException, IOException, com.sshtools.common.permissions.PermissionDeniedException

      Upload a file to the remote computer. If the paths provided are not absolute the current working directory is used.

      Parameters:
      local - the path/name of the local file
      remote - the path/name of the destination file
      progress -
      resume - attempt to resume after an interrupted transfer
      Throws:
      com.sshtools.common.sftp.SftpStatusException
      com.sshtools.common.ssh.SshException
      TransferCancelledException
      com.sshtools.common.permissions.PermissionDeniedException
      IOException
    • append

      public void append(String local, String remote) throws com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException, TransferCancelledException, IOException, com.sshtools.common.permissions.PermissionDeniedException
      Throws:
      com.sshtools.common.sftp.SftpStatusException
      com.sshtools.common.ssh.SshException
      TransferCancelledException
      IOException
      com.sshtools.common.permissions.PermissionDeniedException
    • append

      @Deprecated public void append(String local, String remote, FileTransferProgress progress) throws com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException, TransferCancelledException, IOException, com.sshtools.common.permissions.PermissionDeniedException
      Deprecated.
      Throws:
      com.sshtools.common.sftp.SftpStatusException
      com.sshtools.common.ssh.SshException
      TransferCancelledException
      IOException
      com.sshtools.common.permissions.PermissionDeniedException
    • append

      public void append(String local, String remote, FileTransferProgress progress, long length) throws com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException, TransferCancelledException, IOException, com.sshtools.common.permissions.PermissionDeniedException
      Throws:
      com.sshtools.common.sftp.SftpStatusException
      com.sshtools.common.ssh.SshException
      TransferCancelledException
      IOException
      com.sshtools.common.permissions.PermissionDeniedException
    • put

      public void put(String local, String remote, boolean resume) throws com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException, TransferCancelledException, IOException, com.sshtools.common.permissions.PermissionDeniedException
      Upload a file to the remote computer
      Parameters:
      local -
      remote -
      resume - attempt to resume after an interrupted transfer
      Throws:
      com.sshtools.common.sftp.SftpStatusException
      com.sshtools.common.ssh.SshException
      TransferCancelledException
      com.sshtools.common.permissions.PermissionDeniedException
      IOException
    • put

      public void put(String local, String remote) throws com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException, TransferCancelledException, IOException, com.sshtools.common.permissions.PermissionDeniedException
      Upload a file to the remote computer
      Parameters:
      local -
      remote -
      Throws:
      com.sshtools.common.sftp.SftpStatusException
      com.sshtools.common.ssh.SshException
      TransferCancelledException
      com.sshtools.common.permissions.PermissionDeniedException
      IOException
    • put

      public void put(InputStream in, String remote, FileTransferProgress progress) throws com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException, TransferCancelledException

      Upload a file to the remote computer reading from the specified InputStream. The InputStream is closed, even if the operation fails. The FileTransferProgress will be indeterminate, i.e FileTransferProgress.started(long, String) will be called with a length of -1, as it is not possible to generically determine the length of an InputStream. It is recommended you use put(InputStream, String, FileTransferProgress, long, long) instead to provide the size when known.

      Parameters:
      in - the InputStream being read
      remote - the path/name of the destination file
      progress -
      Throws:
      com.sshtools.common.sftp.SftpStatusException
      com.sshtools.common.ssh.SshException
      TransferCancelledException
    • put

      @Deprecated public void put(InputStream in, String remote, FileTransferProgress progress, long position) throws com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException, TransferCancelledException
      Deprecated.
      Throws:
      com.sshtools.common.sftp.SftpStatusException
      com.sshtools.common.ssh.SshException
      TransferCancelledException
    • put

      public void put(InputStream in, String remote, FileTransferProgress progress, long position, long length) throws com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException, TransferCancelledException

      Upload a file to the remote computer reading from the specified InputStream. The InputStream is closed, even if the operation fails. The FileTransferProgress will be indeterminate if you pass a length of -1. to provide the size when known.

      Parameters:
      in - the InputStream being read
      remote - the path/name of the destination file
      progress - progress
      position - position to start at
      length - the number of bytes that will be transferred or -1 if unknown.
      Throws:
      com.sshtools.common.sftp.SftpStatusException
      com.sshtools.common.ssh.SshException
      TransferCancelledException
    • getOutputStream

      public OutputStream getOutputStream(String remotefile) throws com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException
      Create an OutputStream for writing to a remote file.
      Parameters:
      remotefile -
      Returns:
      OutputStream
      Throws:
      com.sshtools.common.sftp.SftpStatusException
      com.sshtools.common.ssh.SshException
    • put

      public void put(InputStream in, String remote, long position) throws com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException, TransferCancelledException
      Upload the contents of an InputStream to the remote computer.
      Parameters:
      in -
      remote -
      position -
      Throws:
      com.sshtools.common.sftp.SftpStatusException
      com.sshtools.common.ssh.SshException
      TransferCancelledException
    • put

      public void put(InputStream in, String remote) throws com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException, TransferCancelledException
      Upload the contents of an InputStream to the remote computer.
      Parameters:
      in -
      remote -
      Throws:
      com.sshtools.common.sftp.SftpStatusException
      com.sshtools.common.ssh.SshException
      TransferCancelledException
    • chown

      public void chown(String uid, String path) throws com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException

      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:
      com.sshtools.common.sftp.SftpStatusException
      com.sshtools.common.ssh.SshException
      TransferCancelledException
    • chown

      public void chown(String uid, String gid, String path) throws com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException

      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:
      com.sshtools.common.sftp.SftpStatusException
      com.sshtools.common.ssh.SshException
      TransferCancelledException
    • chgrp

      public void chgrp(String gid, String path) throws com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException

      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:
      com.sshtools.common.sftp.SftpStatusException
      com.sshtools.common.ssh.SshException
    • chmod

      public void chmod(com.sshtools.common.sftp.PosixPermissions permissions, String path) throws com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException

      Changes the access permissions or modes of the specified file or directory.

      Modes determine who can read, change or execute a file.

      Parameters:
      permissions - the absolute mode of the file/directory
      path - the path to the file/directory on the remote server
      Throws:
      com.sshtools.common.sftp.SftpStatusException
      com.sshtools.common.ssh.SshException
      See Also:
      • PosixPermissions
      • PosixPermissions.PosixPermissionsBuilder
    • chmod

      @Deprecated(since="3.1.0") public void chmod(int permissions, String path) throws com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException
      Deprecated.

      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.
       
       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
       

      Now deprecated, it is recommended PosixPermissions and PosixPermissions.PosixPermissionsBuilder be used instead.

      Parameters:
      permissions - the absolute mode of the file/directory
      path - the path to the file/directory on the remote server
      Throws:
      com.sshtools.common.sftp.SftpStatusException
      com.sshtools.common.ssh.SshException
    • umask

      public void umask(String umask) throws com.sshtools.common.ssh.SshException
      Sets the umask for this client.
       To give yourself full permissions for both files and directories and
       prevent the group and other users from having access:
       
         umask("077");
       
       This subtracts 077 from the system defaults for files and directories
       666 and 777. Giving a default access permissions for your files of
       600 (rw-------) and for directories of 700 (rwx------).
       
       To give all access permissions to the group and allow other users read
       and execute permission:
       
         umask("002");
       
       This subtracts 002 from the system defaults to give a default access permission
       for your files of 664 (rw-rw-r--) and for your directories of 775 (rwxrwxr-x).
       
       To give the group and other users all access except write access:
       
         umask("022");
       
       This subtracts 022 from the system defaults to give a default access permission
       for your files of 644 (rw-r--r--) and for your directories of 755 (rwxr-xr-x).
       
      Parameters:
      umask -
      Throws:
      com.sshtools.common.ssh.SshException
    • rename

      public void rename(String oldpath, String newpath, boolean posix) throws IOException, com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException
      Rename a file on the remote computer, optionally using posix semantics that allow files to be renamed even if the destination path exists. The server must support posix-rename@openssh.com SFTP extension in order to use the posix operation.
      Parameters:
      oldpath -
      newpath -
      posix -
      Throws:
      IOException
      com.sshtools.common.sftp.SftpStatusException
      com.sshtools.common.ssh.SshException
    • copyRemoteFile

      public void copyRemoteFile(String sourceFile, String destinationFile, boolean overwriteDestination) throws com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException, IOException
      Throws:
      com.sshtools.common.sftp.SftpStatusException
      com.sshtools.common.ssh.SshException
      IOException
    • copyRemoteData

      @Deprecated(since="3.1.0", forRemoval=true) public void copyRemoteData(SftpFile sourceFile, com.sshtools.common.util.UnsignedInteger64 fromOffset, com.sshtools.common.util.UnsignedInteger64 length, SftpFile destinationFile, com.sshtools.common.util.UnsignedInteger64 toOffset) throws com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException, IOException
      Deprecated, for removal: This API element is subject to removal in a future version.
      Copy remotely from one file to another (when supported by extension).
      Parameters:
      sourceFile - source file
      fromOffset - from offset
      length - length
      destinationFile - destination file
      toOffset - to offset
      Throws:
      com.sshtools.common.sftp.SftpStatusException - on SFTP error
      com.sshtools.common.ssh.SshException - on SSH error
      IOException - on IO error
      See Also:
    • rename

      public void rename(String oldpath, String newpath) throws com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException

      Rename a file on the remote computer.

      Parameters:
      oldpath - the old path
      newpath - the new path
      Throws:
      com.sshtools.common.sftp.SftpStatusException
      com.sshtools.common.ssh.SshException
    • rm

      public void rm(String path) throws com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException

      Remove a file or directory from the remote computer.

      Parameters:
      path - the path of the remote file/directory
      Throws:
      com.sshtools.common.sftp.SftpStatusException
      com.sshtools.common.ssh.SshException
    • rm

      public void rm(String path, boolean force, boolean recurse) throws com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException
      Remove a file or directory on the remote computer with options to force deletion of existing files and recursion.
      Parameters:
      path -
      force -
      recurse -
      Throws:
      com.sshtools.common.sftp.SftpStatusException
      com.sshtools.common.ssh.SshException
    • rmdir

      public void rmdir(String path) throws com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException
      Remove a directory, will fail if the directory has contents.
      Parameters:
      path -
      Throws:
      com.sshtools.common.sftp.SftpStatusException
      com.sshtools.common.ssh.SshException
    • symlink

      public void symlink(String path, String link) throws com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException

      Create a symbolic link on the remote computer.

      Parameters:
      path - the path to the existing file
      link - the new link
      Throws:
      com.sshtools.common.sftp.SftpStatusException
      com.sshtools.common.ssh.SshException
    • relativeSymlink

      public void relativeSymlink(String path, String link) throws com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException

      Create a symbolic link on the remote computer.

      Parameters:
      path - the path to the existing file
      link - the new link
      Throws:
      com.sshtools.common.sftp.SftpStatusException
      com.sshtools.common.ssh.SshException
    • stat

      public com.sshtools.common.sftp.SftpFileAttributes stat(String path) throws com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException

      Returns the attributes of the file from the remote computer.

      Parameters:
      path - the path of the file on the remote computer
      Returns:
      the attributes
      Throws:
      com.sshtools.common.sftp.SftpStatusException
      com.sshtools.common.ssh.SshException
    • statLink

      public com.sshtools.common.sftp.SftpFileAttributes statLink(String path) throws com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException

      Returns the attributes of the link from the remote computer.

      Parameters:
      path - the path of the file on the remote computer
      Returns:
      the attributes
      Throws:
      com.sshtools.common.sftp.SftpStatusException
      com.sshtools.common.ssh.SshException
    • getAbsolutePath

      public String getAbsolutePath(String path) throws com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException
      Get the absolute path for a file.
      Parameters:
      path -
      Returns:
      String
      Throws:
      com.sshtools.common.sftp.SftpStatusException
      com.sshtools.common.ssh.SshException
    • verifyFiles

      public boolean verifyFiles(String localFile, String remoteFile) throws com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException, IOException, com.sshtools.common.permissions.PermissionDeniedException
      Verify a local and remote file. Requires a minimum SFTP version of 5 and/or support of the "md5-hash" extension
      Parameters:
      localFile -
      remoteFile -
      Returns:
      Throws:
      com.sshtools.common.sftp.SftpStatusException
      com.sshtools.common.ssh.SshException
      IOException
      com.sshtools.common.permissions.PermissionDeniedException
    • verifyFiles

      public boolean verifyFiles(String localFile, String remoteFile, RemoteHash algorithm) throws com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException, IOException, com.sshtools.common.permissions.PermissionDeniedException
      Throws:
      com.sshtools.common.sftp.SftpStatusException
      com.sshtools.common.ssh.SshException
      IOException
      com.sshtools.common.permissions.PermissionDeniedException
    • verifyFiles

      public boolean verifyFiles(String localFile, String remoteFile, long offset, long length) throws com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException, IOException, com.sshtools.common.permissions.PermissionDeniedException
      Verify a local and remote file. Requires a minimum SFTP version of 5 and/or support of the "md5-hash" extension.
      Parameters:
      localFile -
      remoteFile -
      offset -
      length -
      Returns:
      Throws:
      com.sshtools.common.sftp.SftpStatusException
      com.sshtools.common.ssh.SshException
      IOException
      com.sshtools.common.permissions.PermissionDeniedException
    • verifyFiles

      public boolean verifyFiles(String localFile, String remoteFile, long offset, long length, RemoteHash algorithm) throws com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException, IOException, com.sshtools.common.permissions.PermissionDeniedException
      Throws:
      com.sshtools.common.sftp.SftpStatusException
      com.sshtools.common.ssh.SshException
      IOException
      com.sshtools.common.permissions.PermissionDeniedException
    • getRemoteHash

      @Deprecated public byte[] getRemoteHash(String remoteFile) throws IOException, com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException
      Deprecated.
      Throws:
      IOException
      com.sshtools.common.sftp.SftpStatusException
      com.sshtools.common.ssh.SshException
    • getRemoteHash

      @Deprecated public byte[] getRemoteHash(String remoteFile, long offset, long length, byte[] quickCheck) throws IOException, com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException
      Deprecated.
      Throws:
      IOException
      com.sshtools.common.sftp.SftpStatusException
      com.sshtools.common.ssh.SshException
    • getRemoteHash

      @Deprecated public byte[] getRemoteHash(byte[] handle) throws IOException, com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException
      Deprecated.
      Throws:
      IOException
      com.sshtools.common.sftp.SftpStatusException
      com.sshtools.common.ssh.SshException
    • getRemoteHash

      @Deprecated public byte[] getRemoteHash(byte[] handle, long offset, long length, byte[] quickCheck) throws IOException, com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException
      Deprecated.
      Throws:
      IOException
      com.sshtools.common.sftp.SftpStatusException
      com.sshtools.common.ssh.SshException
    • getRemoteHash

      public byte[] getRemoteHash(byte[] handle, RemoteHash algorithm) throws IOException, com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException
      Throws:
      IOException
      com.sshtools.common.sftp.SftpStatusException
      com.sshtools.common.ssh.SshException
    • getRemoteHash

      public byte[] getRemoteHash(byte[] handle, long offset, long length, RemoteHash algorithm) throws IOException, com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException
      Throws:
      IOException
      com.sshtools.common.sftp.SftpStatusException
      com.sshtools.common.ssh.SshException
    • getRemoteHash

      public byte[] getRemoteHash(String path, RemoteHash algorithm) throws IOException, com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException
      Throws:
      IOException
      com.sshtools.common.sftp.SftpStatusException
      com.sshtools.common.ssh.SshException
    • getRemoteHash

      public byte[] getRemoteHash(String path, long offset, long length, RemoteHash algorithm) throws IOException, com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException
      Throws:
      IOException
      com.sshtools.common.sftp.SftpStatusException
      com.sshtools.common.ssh.SshException
    • doCheckHashHandle

      protected byte[] doCheckHashHandle(byte[] handle, long offset, long length, RemoteHash algorithm) throws IOException, com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException
      Throws:
      IOException
      com.sshtools.common.sftp.SftpStatusException
      com.sshtools.common.ssh.SshException
    • doCheckFileHandle

      protected byte[] doCheckFileHandle(String filename, long offset, long length, RemoteHash algorithm) throws IOException, com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException
      Throws:
      IOException
      com.sshtools.common.sftp.SftpStatusException
      com.sshtools.common.ssh.SshException
    • processCheckFileResponse

      protected byte[] processCheckFileResponse(SftpMessage resp, RemoteHash algorithm) throws IOException
      Throws:
      IOException
    • doMD5HashHandle

      protected byte[] doMD5HashHandle(byte[] handle, long offset, long length, byte[] quickCheck) throws IOException, com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException
      Throws:
      IOException
      com.sshtools.common.sftp.SftpStatusException
      com.sshtools.common.ssh.SshException
    • quit

      public void quit() throws com.sshtools.common.ssh.SshException

      Close the SFTP client.

      Throws:
      com.sshtools.common.ssh.SshException
    • exit

      public void exit() throws com.sshtools.common.ssh.SshException

      Close the SFTP client.

      Throws:
      com.sshtools.common.ssh.SshException
    • putLocalDirectory

      public DirectoryOperation putLocalDirectory(String localdir, String remotedir, boolean recurse, boolean sync, boolean commit, FileTransferProgress progress) throws IOException, com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException, TransferCancelledException, com.sshtools.common.permissions.PermissionDeniedException
      Copy the contents of a local directory into a remote directory.
      Parameters:
      localdir - the path to the local directory
      remotedir - the remote directory which will receive the contents
      recurse - recurse through child folders
      sync - synchronize the directories by removing files on the remote server that do not exist locally
      commit - actually perform the operation. If false a DirectoryOperation will be returned so that the operation can be evaluated and no actual files will be created/transfered.
      progress -
      Returns:
      DirectoryOperation
      Throws:
      com.sshtools.common.sftp.SftpStatusException
      com.sshtools.common.ssh.SshException
      TransferCancelledException
      com.sshtools.common.permissions.PermissionDeniedException
      IOException
    • formatLongname

      public static String formatLongname(SftpFile file) throws com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException
      Format a String with the details of the file.
       -rwxr-xr-x   1 mjos     staff      348911 Mar 25 14:29 t-filexfer
       
      Parameters:
      file -
      Returns:
      String
      Throws:
      com.sshtools.common.sftp.SftpStatusException
      com.sshtools.common.ssh.SshException
    • formatLongname

      public static String formatLongname(com.sshtools.common.sftp.SftpFileAttributes attrs, String filename)
      Format a String with the details of the file.
       -rwxr-xr-x   1 mjos     staff      348911 Mar 25 14:29 t-filexfer
       
      Parameters:
      attrs -
      filename -
      Returns:
      String
    • getRemoteDirectory

      public DirectoryOperation getRemoteDirectory(String remotedir, String localdir, boolean recurse, boolean sync, boolean commit, FileTransferProgress progress) throws IOException, com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException, TransferCancelledException, com.sshtools.common.permissions.PermissionDeniedException
      Copy the contents of a remote directory to a local directory
      Parameters:
      remotedir - the remote directory whose contents will be copied.
      localdir - the local directory to where the contents will be copied
      recurse - recurse into child folders
      sync - synchronized the directories by removing files and directories that do not exist on the remote server.
      commit - actually perform the operation. If false the operation will be processed and a DirectoryOperation will be returned without actually transfering any files.
      progress -
      Returns:
      DirectoryOperation
      Throws:
      IOException
      com.sshtools.common.sftp.SftpStatusException
      com.sshtools.common.ssh.SshException
      TransferCancelledException
      com.sshtools.common.permissions.PermissionDeniedException
    • getFiles

      public SftpFile[] getFiles(String remote) throws IOException, com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException, TransferCancelledException, com.sshtools.common.permissions.PermissionDeniedException

      Download the remote files to the local computer

      When RegExpSyntax is set to NoSyntax the getFiles() methods act identically to the get() methods except for a different return type.

      When RegExpSyntax is set to GlobSyntax or Perl5Syntax, getFiles() treats 'remote' as a regular expression, and gets all the files in 'remote''s parent directory that match the pattern. The default parent directory of remote is the remote cwd unless 'remote' contains file seperators(/).

      Examples can be found in SftpConnect.java

      Code Example:

       // change reg exp syntax from default SftpClient.NoSyntax (no reg exp matching)
       // to SftpClient.GlobSyntax
       sftp.setRegularExpressionSyntax(SftpClient.GlobSyntax);
       // get all .doc files with 'rfc' in their names, in the 'docs/unsorted/' folder
       // relative to the remote cwd, and copy them to the local cwd.
       sftp.getFiles("docs/unsorted/*rfc*.doc");
       

      Parameters:
      remote - the regular expression path to the remote file
      Returns:
      the downloaded files' attributes
      Throws:
      IOException
      com.sshtools.common.sftp.SftpStatusException
      com.sshtools.common.ssh.SshException
      TransferCancelledException
      com.sshtools.common.permissions.PermissionDeniedException
    • getFiles

      public SftpFile[] getFiles(String remote, boolean resume) throws IOException, com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException, TransferCancelledException, com.sshtools.common.permissions.PermissionDeniedException

      Download the remote files to the local computer

      Parameters:
      remote - the regular expression path to the remote file
      resume - attempt to resume an interrupted download
      Returns:
      the downloaded files' attributes
      Throws:
      IOException
      com.sshtools.common.sftp.SftpStatusException
      com.sshtools.common.ssh.SshException
      TransferCancelledException
      com.sshtools.common.permissions.PermissionDeniedException
    • getFiles

      public SftpFile[] getFiles(String remote, FileTransferProgress progress) throws IOException, com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException, TransferCancelledException, com.sshtools.common.permissions.PermissionDeniedException

      Download the remote files to the local computer.

      Parameters:
      remote - the regular expression path to the remote file
      progress -
      Returns:
      SftpFile[]
      Throws:
      IOException
      com.sshtools.common.sftp.SftpStatusException
      com.sshtools.common.ssh.SshException
      TransferCancelledException
      com.sshtools.common.permissions.PermissionDeniedException
    • getFiles

      public SftpFile[] getFiles(String remote, FileTransferProgress progress, boolean resume) throws IOException, com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException, TransferCancelledException, com.sshtools.common.permissions.PermissionDeniedException

      Download the remote files to the local computer.

      Parameters:
      remote - the regular expression path to the remote file
      progress -
      resume - attempt to resume a interrupted download
      Returns:
      SftpFile[]
      Throws:
      IOException
      com.sshtools.common.sftp.SftpStatusException
      com.sshtools.common.ssh.SshException
      TransferCancelledException
      com.sshtools.common.permissions.PermissionDeniedException
    • getFiles

      public SftpFile[] getFiles(String remote, String local) throws IOException, com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException, TransferCancelledException, com.sshtools.common.permissions.PermissionDeniedException
      Download the remote files into the local file.
      Parameters:
      remote -
      local -
      Returns:
      SftpFile[]
      Throws:
      IOException
      com.sshtools.common.sftp.SftpStatusException
      com.sshtools.common.ssh.SshException
      TransferCancelledException
      com.sshtools.common.permissions.PermissionDeniedException
    • getFiles

      public SftpFile[] getFiles(String remote, String local, boolean resume) throws IOException, com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException, TransferCancelledException, com.sshtools.common.permissions.PermissionDeniedException
      Download the remote files into the local file.
      Parameters:
      remote -
      local -
      resume - attempt to resume an interrupted download
      Returns:
      SftpFile[]
      Throws:
      IOException
      com.sshtools.common.sftp.SftpStatusException
      com.sshtools.common.ssh.SshException
      TransferCancelledException
      com.sshtools.common.permissions.PermissionDeniedException
    • getFiles

      public SftpFile[] getFiles(String remote, String local, FileTransferProgress progress, boolean resume) throws IOException, com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException, TransferCancelledException, com.sshtools.common.permissions.PermissionDeniedException

      Download the remote file to the local computer. If the paths provided are not absolute the current working directory is used.

      Parameters:
      remote - the regular expression path/name of the remote files
      local - the path/name to place the file on the local computer
      progress -
      Returns:
      SftpFile[]
      Throws:
      com.sshtools.common.sftp.SftpStatusException
      IOException
      com.sshtools.common.ssh.SshException
      TransferCancelledException
      com.sshtools.common.permissions.PermissionDeniedException
    • putFiles

      public void putFiles(String local) throws IOException, com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException, TransferCancelledException, com.sshtools.common.permissions.PermissionDeniedException

      Upload the contents of an InputStream to the remote computer.

      When RegExpSyntax is set to NoSyntax the putFiles() methods act identically to the put() methods except for a different return type.

      When RegExpSyntax is set to GlobSyntax or Perl5Syntax, putFiles() treats 'local' as a regular expression, and gets all the files in 'local''s parent directory that match the pattern. The default parent directory of local is the local cwd unless 'local' contains file seperators.

      Examples can be found in SftpConnect.java

      Code Example:

       // change reg exp syntax from default SftpClient.NoSyntax (no reg exp matching)
       // to SftpClient.GlobSyntax
       sftp.setRegularExpressionSyntax(SftpClient.GlobSyntax);
       // put all .doc files with 'rfc' in their names, in the 'docs/unsorted/' folder
       // relative to the local cwd, and copy them to the remote cwd.
       sftp.putFiles("docs/unsorted/*rfc*.doc");
       

      Parameters:
      local -
      Throws:
      com.sshtools.common.sftp.SftpStatusException
      com.sshtools.common.ssh.SshException
      TransferCancelledException
      IOException
      com.sshtools.common.permissions.PermissionDeniedException
    • putFiles

      public void putFiles(String local, boolean resume) throws IOException, com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException, TransferCancelledException, com.sshtools.common.permissions.PermissionDeniedException
      Upload files to the remote computer
      Parameters:
      local -
      resume - attempt to resume after an interrupted transfer
      Throws:
      com.sshtools.common.sftp.SftpStatusException
      com.sshtools.common.ssh.SshException
      TransferCancelledException
      IOException
      com.sshtools.common.permissions.PermissionDeniedException
    • putFiles

      public void putFiles(String local, FileTransferProgress progress) throws IOException, com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException, TransferCancelledException, com.sshtools.common.permissions.PermissionDeniedException

      Upload files to the remote computer

      Parameters:
      local - the regular expression path/name of the local files
      progress -
      Throws:
      com.sshtools.common.sftp.SftpStatusException
      com.sshtools.common.ssh.SshException
      TransferCancelledException
      IOException
      com.sshtools.common.permissions.PermissionDeniedException
    • putFiles

      public void putFiles(String local, FileTransferProgress progress, boolean resume) throws IOException, com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException, TransferCancelledException, com.sshtools.common.permissions.PermissionDeniedException

      Upload files to the remote computer

      Parameters:
      local - the regular expression path/name of the local files
      progress -
      Throws:
      com.sshtools.common.sftp.SftpStatusException
      com.sshtools.common.ssh.SshException
      TransferCancelledException
      IOException
      com.sshtools.common.permissions.PermissionDeniedException
    • putFiles

      public void putFiles(String local, String remote) throws IOException, com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException, TransferCancelledException, com.sshtools.common.permissions.PermissionDeniedException
      Upload files to the remote computer
      Parameters:
      local -
      remote -
      Throws:
      com.sshtools.common.sftp.SftpStatusException
      com.sshtools.common.ssh.SshException
      TransferCancelledException
      IOException
      com.sshtools.common.permissions.PermissionDeniedException
    • putFiles

      public void putFiles(String local, String remote, boolean resume) throws IOException, com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException, TransferCancelledException, com.sshtools.common.permissions.PermissionDeniedException
      Upload files to the remote computer
      Parameters:
      local -
      remote -
      resume - attempt to resume after an interrupted transfer
      Throws:
      com.sshtools.common.sftp.SftpStatusException
      com.sshtools.common.ssh.SshException
      TransferCancelledException
      IOException
      com.sshtools.common.permissions.PermissionDeniedException
    • putFiles

      public void putFiles(String local, String remote, FileTransferProgress progress) throws IOException, com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException, TransferCancelledException, com.sshtools.common.permissions.PermissionDeniedException

      Upload files to the remote computer. If the paths provided are not absolute the current working directory is used.

      Parameters:
      local - the regular expression path/name of the local files
      remote - the path/name of the destination file
      progress -
      Throws:
      com.sshtools.common.sftp.SftpStatusException
      com.sshtools.common.ssh.SshException
      TransferCancelledException
      IOException
      com.sshtools.common.permissions.PermissionDeniedException
    • putFiles

      public void putFiles(String local, String remote, FileTransferProgress progress, boolean resume) throws IOException, com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException, TransferCancelledException, com.sshtools.common.permissions.PermissionDeniedException
      make local copies of some of the variables, then call putfilematches, which calls "put" on each file that matches the regexp local.
      Parameters:
      local - the regular expression path/name of the local files
      remote - the path/name of the destination file
      progress -
      resume - attempt to resume after an interrupted transfer
      Throws:
      com.sshtools.common.sftp.SftpStatusException
      com.sshtools.common.ssh.SshException
      TransferCancelledException
      IOException
      com.sshtools.common.permissions.PermissionDeniedException
    • isConnected

      public boolean isConnected()
    • hardlink

      public void hardlink(String src, String dst) throws com.sshtools.common.ssh.SshException, com.sshtools.common.sftp.SftpStatusException
      Throws:
      com.sshtools.common.ssh.SshException
      com.sshtools.common.sftp.SftpStatusException
    • getHomeDirectory

      public String getHomeDirectory(String username) throws com.sshtools.common.ssh.SshException, com.sshtools.common.sftp.SftpStatusException
      Throws:
      com.sshtools.common.ssh.SshException
      com.sshtools.common.sftp.SftpStatusException
    • makeTemporaryFolder

      public String makeTemporaryFolder() throws com.sshtools.common.ssh.SshException, com.sshtools.common.sftp.SftpStatusException
      Throws:
      com.sshtools.common.ssh.SshException
      com.sshtools.common.sftp.SftpStatusException
    • getTemporaryFolder

      public String getTemporaryFolder() throws com.sshtools.common.ssh.SshException, com.sshtools.common.sftp.SftpStatusException
      Throws:
      com.sshtools.common.ssh.SshException
      com.sshtools.common.sftp.SftpStatusException
    • statVFS

      public StatVfs statVFS(String path) throws com.sshtools.common.ssh.SshException, com.sshtools.common.sftp.SftpStatusException
      Throws:
      com.sshtools.common.ssh.SshException
      com.sshtools.common.sftp.SftpStatusException
    • getHome

      public String getHome() throws com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException
      Throws:
      com.sshtools.common.sftp.SftpStatusException
      com.sshtools.common.ssh.SshException
    • close

      public void close() throws IOException
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Throws:
      IOException
    • visit

      public FileVisitResult visit(String path, FileVisitor<SftpFile> visitor) throws com.sshtools.common.ssh.SshException, com.sshtools.common.sftp.SftpStatusException
      Throws:
      com.sshtools.common.ssh.SshException
      com.sshtools.common.sftp.SftpStatusException