Class SftpChannel


public class SftpChannel extends AbstractSubsystem
Abstract task implementing SFTP operations.
  • Field Details

    • OPEN_READ

      public static final int OPEN_READ
      File open flag, opens the file for reading.
      See Also:
    • OPEN_WRITE

      public static final int OPEN_WRITE
      File open flag, opens the file for writing.
      See Also:
    • OPEN_APPEND

      public static final int OPEN_APPEND
      File open flag, forces all writes to append data at the end of the file.
      See Also:
    • OPEN_CREATE

      public static final int OPEN_CREATE
      File open flag, if specified a new file will be created if one does not already exist.
      See Also:
    • OPEN_TRUNCATE

      public static final int OPEN_TRUNCATE
      File open flag, forces an existing file with the same name to be truncated to zero length when creating a file by specifying OPEN_CREATE.
      See Also:
    • OPEN_EXCLUSIVE

      public static final int OPEN_EXCLUSIVE
      File open flag, causes an open request to fail if the named file already exists. OPEN_CREATE must also be specified if this flag is used.
      See Also:
    • OPEN_TEXT

      public static final int OPEN_TEXT
      File open flag, causes the file to be opened in text mode. This instructs the server to convert the text file to the canonical newline convention in use. Any files retrieved using this mode should then be converted from the canonical newline convention to that of the clients.
      See Also:
    • SSH_FXP_STATUS

      public static final int SSH_FXP_STATUS
      See Also:
    • SSH_FXP_HANDLE

      public static final int SSH_FXP_HANDLE
      See Also:
    • SSH_FXP_DATA

      public static final int SSH_FXP_DATA
      See Also:
    • SSH_FXP_NAME

      public static final int SSH_FXP_NAME
      See Also:
    • SSH_FXP_ATTRS

      public static final int SSH_FXP_ATTRS
      See Also:
    • SSH_FXP_EXTENDED

      public static final int SSH_FXP_EXTENDED
      See Also:
    • SSH_FXP_EXTENDED_REPLY

      public static final int SSH_FXP_EXTENDED_REPLY
      See Also:
    • MAX_VERSION

      public static final int MAX_VERSION
      See Also:
    • SSH_FXF_ACCESS_DISPOSITION

      public static final int SSH_FXF_ACCESS_DISPOSITION
      Version 5 new flags
      See Also:
    • SSH_FXF_CREATE_NEW

      public static final int SSH_FXF_CREATE_NEW
      See Also:
    • SSH_FXF_CREATE_TRUNCATE

      public static final int SSH_FXF_CREATE_TRUNCATE
      See Also:
    • SSH_FXF_OPEN_EXISTING

      public static final int SSH_FXF_OPEN_EXISTING
      See Also:
    • SSH_FXF_OPEN_OR_CREATE

      public static final int SSH_FXF_OPEN_OR_CREATE
      See Also:
    • SSH_FXF_TRUNCATE_EXISTING

      public static final int SSH_FXF_TRUNCATE_EXISTING
      See Also:
    • SSH_FXF_ACCESS_APPEND_DATA

      public static final int SSH_FXF_ACCESS_APPEND_DATA
      See Also:
    • SSH_FXF_ACCESS_APPEND_DATA_ATOMIC

      public static final int SSH_FXF_ACCESS_APPEND_DATA_ATOMIC
      See Also:
    • SSH_FXF_ACCESS_TEXT_MODE

      public static final int SSH_FXF_ACCESS_TEXT_MODE
      See Also:
    • SSH_FXF_ACCESS_BLOCK_READ

      public static final int SSH_FXF_ACCESS_BLOCK_READ
      See Also:
    • SSH_FXF_ACCESS_BLOCK_WRITE

      public static final int SSH_FXF_ACCESS_BLOCK_WRITE
      See Also:
    • SSH_FXF_ACCESS_BLOCK_DELETE

      public static final int SSH_FXF_ACCESS_BLOCK_DELETE
      See Also:
    • SSH_FXF_ACCESS_BLOCK_ADVISORY

      public static final int SSH_FXF_ACCESS_BLOCK_ADVISORY
      See Also:
    • SSH_FXF_NOFOLLOW

      public static final int SSH_FXF_NOFOLLOW
      See Also:
    • SSH_FXF_DELETE_ON_CLOSE

      public static final int SSH_FXF_DELETE_ON_CLOSE
      See Also:
    • SSH_FXF_ACCESS_AUDIT_ALARM_INFO

      public static final int SSH_FXF_ACCESS_AUDIT_ALARM_INFO
      See Also:
    • SSH_FXF_ACCESS_BACKUP

      public static final int SSH_FXF_ACCESS_BACKUP
      See Also:
    • SSH_FXF_BACKUP_STREAM

      public static final int SSH_FXF_BACKUP_STREAM
      See Also:
    • SSH_FXF_OVERRIDE_OWNER

      public static final int SSH_FXF_OVERRIDE_OWNER
      See Also:
    • SSH_FXP_RENAME_OVERWRITE

      public static final int SSH_FXP_RENAME_OVERWRITE
      See Also:
    • SSH_FXP_RENAME_ATOMIC

      public static final int SSH_FXP_RENAME_ATOMIC
      See Also:
    • SSH_FXP_RENAME_NATIVE

      public static final int SSH_FXP_RENAME_NATIVE
      See Also:
  • Constructor Details

    • SftpChannel

      public SftpChannel(com.sshtools.common.ssh.SshConnection con) throws com.sshtools.common.ssh.SshException
      Throws:
      com.sshtools.common.ssh.SshException
  • Method Details

    • getVersion

      public int getVersion()
    • getMinimumWindowSize

      protected com.sshtools.common.util.UnsignedInteger32 getMinimumWindowSize()
      Specified by:
      getMinimumWindowSize in class AbstractSubsystem
    • getMaximumWindowSize

      protected com.sshtools.common.util.UnsignedInteger32 getMaximumWindowSize()
      Specified by:
      getMaximumWindowSize in class AbstractSubsystem
    • getMaximumPacketSize

      protected int getMaximumPacketSize()
      Specified by:
      getMaximumPacketSize in class AbstractSubsystem
    • getExtensions

      public Map<String,byte[]> getExtensions()
    • getSession

      public SessionChannelNG getSession()
      Overrides:
      getSession in class AbstractSubsystem
    • getCanonicalNewline

      public byte[] getCanonicalNewline() throws com.sshtools.common.sftp.SftpStatusException
      Returns the canonical newline convention in use when reading/writing text files.
      Returns:
      String
      Throws:
      com.sshtools.common.sftp.SftpStatusException
    • processSupported2

      protected void processSupported2(byte[] data) throws IOException
      Throws:
      IOException
    • processSupported

      protected void processSupported(byte[] data) throws IOException
      Throws:
      IOException
    • setCharsetEncoding

      public void setCharsetEncoding(String charset) throws com.sshtools.common.ssh.SshException, UnsupportedEncodingException
      Allows the default character encoding to be overriden for filename strings. This method should only be called once the channel has been initialized, if the version of the protocol is less than or equal to 3 the encoding is defaulted to latin1 as no encoding is specified by the protocol. If the version is greater than 3 the default encoding will be UTF-8.
      Parameters:
      charset -
      Throws:
      UnsupportedEncodingException
      com.sshtools.common.ssh.SshException
    • getServerVersion

      public int getServerVersion()
      Version 4 of the SFTP protocol allows the server to return its maximum supported version instead of the actual version to be used. This method returns the value provided by the server, if the servers version is less than or equal to 3 then this method will return the protocol number in use, otherwise it returns the maximum version supported by the server.
      Returns:
      int
    • getCharsetEncoding

      public String getCharsetEncoding()
      Get the current encoding being used for filename Strings.
      Returns:
      String
    • supportsExtension

      public boolean supportsExtension(String name)
      Does the server support an SFTP extension? This checks the extensions returned by the server during the SFTP version negotiation.
      Parameters:
      name - String
      Returns:
      boolean
    • getExtension

      public byte[] getExtension(String name)
      Get the data value of a supported SFTP extension. Call supportsExtension(java.lang.String) before calling this method to determine if the extension is available.
      Parameters:
      name - String
      Returns:
      String
    • close

      public void close()
    • getResponse

      public SftpMessage getResponse(com.sshtools.common.util.UnsignedInteger32 requestId) throws com.sshtools.common.ssh.SshException
      Throws:
      com.sshtools.common.ssh.SshException
    • changePermissions

      @Deprecated(since="3.1.0", forRemoval=true) public void changePermissions(byte[] file, int permissions) throws com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException
      Deprecated, for removal: This API element is subject to removal in a future version.
      Change the permissions of a file.
      Parameters:
      file - the file
      permissions - an integer value containing a file permissions mask
      Throws:
      com.sshtools.common.ssh.SshException - ,SftpStatusException
      com.sshtools.common.sftp.SftpStatusException
      See Also:
      • }
    • changePermissions

      @Deprecated(since="3.1.0", forRemoval=true) public void changePermissions(String filename, int permissions) throws com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException
      Deprecated, for removal: This API element is subject to removal in a future version.
      Change the permissions of a file.
      Parameters:
      filename - the path to the file.
      permissions - an integer value containing a file permissions mask.
      Throws:
      com.sshtools.common.ssh.SshException - ,SftpStatusException
      com.sshtools.common.sftp.SftpStatusException
      See Also:
    • changePermissions

      public void changePermissions(byte[] handle, com.sshtools.common.sftp.PosixPermissions permissions) throws com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException
      Change the permissions of a file.
      Parameters:
      handle - the file
      permissions - permissions set.
      Throws:
      com.sshtools.common.ssh.SshException - ,SftpStatusException
      com.sshtools.common.sftp.SftpStatusException
    • changePermissions

      public void changePermissions(String filename, com.sshtools.common.sftp.PosixPermissions permissions) throws com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException
      Change the permissions of a file.
      Parameters:
      filename - the path to the file.
      permissions - permissions set.
      Throws:
      com.sshtools.common.ssh.SshException - ,SftpStatusException
      com.sshtools.common.sftp.SftpStatusException
    • changePermissions

      public void changePermissions(String filename, String permissions) throws com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException
      Change the permissions of a file.
      Parameters:
      filename - the path to the file.
      permissions - a string containing the permissions, for example "rw-r--r--"
      Throws:
      com.sshtools.common.sftp.SftpStatusException - , SshException
      com.sshtools.common.ssh.SshException
    • getOKRequestStatus

      public void getOKRequestStatus(com.sshtools.common.util.UnsignedInteger32 requestId) throws com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException
      Verify that an OK status has been returned for a request id.
      Parameters:
      requestId -
      Throws:
      com.sshtools.common.sftp.SftpStatusException - , SshException
      com.sshtools.common.ssh.SshException
    • setAttributes

      @Deprecated(since="3.1.0", forRemoval=true) public void setAttributes(SftpFile path, com.sshtools.common.sftp.SftpFileAttributes attrs) throws com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException
      Deprecated, for removal: This API element is subject to removal in a future version.
      Set the attributes of a file.
      Parameters:
      path - the path to the file
      attrs - the file attributes
      Throws:
      com.sshtools.common.sftp.SftpStatusException
      com.sshtools.common.ssh.SshException
      See Also:
    • setAttributes

      public void setAttributes(String path, com.sshtools.common.sftp.SftpFileAttributes attrs) throws com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException
      Sets the attributes of a file.
      Parameters:
      path - the path to the file.
      attrs - the file attributes.
      Throws:
      com.sshtools.common.sftp.SftpStatusException - , SshException // * @deprecated
      com.sshtools.common.ssh.SshException
      See Also:
    • setAttributes

      @Deprecated(since="3.1.0", forRemoval=true) public void setAttributes(byte[] handle, com.sshtools.common.sftp.SftpFileAttributes attrs) throws com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException
      Deprecated, for removal: This API element is subject to removal in a future version.
      Sets the attributes of a file.
      Parameters:
      handle - the file object.
      attrs - the new attributes.
      Throws:
      com.sshtools.common.ssh.SshException
      com.sshtools.common.sftp.SftpStatusException
      See Also:
      • SftpHandle#setAttributes(byte[], SftpFileAttributes)
    • postWriteRequest

      @Deprecated(since="3.1.0", forRemoval=true) public com.sshtools.common.util.UnsignedInteger32 postWriteRequest(byte[] handle, long position, byte[] data, int off, int len) throws com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException
      Deprecated, for removal: This API element is subject to removal in a future version.
      Send a write request for an open file but do not wait for the response from the server.
      Parameters:
      handle -
      position -
      data -
      off -
      len -
      Returns:
      UnsignedInteger32
      Throws:
      com.sshtools.common.ssh.SshException
      com.sshtools.common.sftp.SftpStatusException
      See Also:
    • writeFile

      public void writeFile(byte[] handle, com.sshtools.common.util.UnsignedInteger64 offset, byte[] data, int off, int len) throws com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException
      Write a block of data to an open file.
      Parameters:
      handle - the open file handle.
      offset - the offset in the file to start writing
      data - a buffer containing the data to write
      off - the offset to start in the buffer
      len - the length of data to write (setting to false will increase file transfer but may miss errors)
      Throws:
      com.sshtools.common.ssh.SshException
      com.sshtools.common.sftp.SftpStatusException
    • performOptimizedWrite

      public void performOptimizedWrite(String filename, byte[] handle, int blocksize, int maxAsyncRequests, InputStream in, int buffersize, FileTransferProgress progress) throws com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException, TransferCancelledException
      Deprecated.
      Performs an optimized write of a file through asynchronous messaging and through buffering the local file into memory.
      Parameters:
      handle - the open file handle to write to
      blocksize - the block size to send data, should be between 4096 and 65536
      outstandingRequests - the maximum number of requests that can be outstanding at any one time
      in - the InputStream to read from
      buffersize - the size of the temporary buffer to read from the InputStream. Data is buffered into a temporary buffer so that the number of local filesystem reads is reducted to a minimum. This increases performance and so the buffer size should be as high as possible. The default operation, if buffersize <= 0 is to allocate a buffer the same size as the blocksize, meaning no buffer optimization is performed.
      progress - provides progress information, may be null.
      Throws:
      com.sshtools.common.ssh.SshException
      com.sshtools.common.sftp.SftpStatusException
      TransferCancelledException
      See Also:
    • performOptimizedWrite

      @Deprecated(since="3.1.0", forRemoval=true) public void performOptimizedWrite(String filename, byte[] handle, int blocksize, int maxAsyncRequests, InputStream in, int buffersize, FileTransferProgress progress, long position) throws com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException, TransferCancelledException
      Deprecated, for removal: This API element is subject to removal in a future version.
      Performs an optimized write of a file through asynchronous messaging and through buffering the local file into memory.
      Parameters:
      handle - the open file handle to write to
      blocksize - the block size to send data, should be between 4096 and 65536
      outstandingRequests - the maximum number of requests that can be outstanding at any one time
      in - the InputStream to read from
      buffersize - the size of the temporary buffer to read from the InputStream. Data is buffered into a temporary buffer so that the number of local filesystem reads is reducted to a minimum. This increases performance and so the buffer size should be as high as possible. The default operation, if buffersize <= 0 is to allocate a buffer the same size as the blocksize, meaning no buffer optimization is performed.
      progress - provides progress information, may be null.
      position - the position in the file to start writing to.
      Throws:
      com.sshtools.common.ssh.SshException
      com.sshtools.common.sftp.SftpStatusException
      TransferCancelledException
      See Also:
    • performOptimizedRead

      @Deprecated(since="3.1.0", forRemoval=true) public void performOptimizedRead(String filename, byte[] handle, long length, int blocksize, OutputStream out, int outstandingRequests, FileTransferProgress progress) throws com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException, TransferCancelledException
      Deprecated, for removal: This API element is subject to removal in a future version.
      Performs an optimized read of a file through use of asynchronous messages. The total number of outstanding read requests is configurable. This should be safe on file objects as the SSH protocol states that file read operations should return the exact number of bytes requested in each request. However the server is not required to return the exact number of bytes on device files and so this method should not be used for device files.
      Parameters:
      handle - the open files handle
      length - the length of the file
      blocksize - the blocksize to read
      out - an OutputStream to output the file into
      outstandingRequests - the maximum number of read requests to
      progress -
      Throws:
      com.sshtools.common.ssh.SshException
      com.sshtools.common.sftp.SftpStatusException
      TransferCancelledException
      See Also:
    • performOptimizedRead

      @Deprecated(since="3.1.0", forRemoval=true) public void performOptimizedRead(String filename, byte[] handle, long length, int blocksize, OutputStream out, int outstandingRequests, FileTransferProgress progress, long position) throws com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException, TransferCancelledException
      Deprecated, for removal: This API element is subject to removal in a future version.
      Performs an optimized read of a file through use of asynchronous messages. The total number of outstanding read requests is configurable. This should be safe on file objects as the SSH protocol states that file read operations should return the exact number of bytes requested in each request. However the server is not required to return the exact number of bytes on device files and so this method should not be used for device files.
      Parameters:
      handle - the open files handle
      length - the amount of the file file to be read, equal to the file length when reading the whole file
      blocksize - the blocksize to read
      out - an OutputStream to output the file into
      outstandingRequests - the maximum number of read requests to
      progress -
      position - the postition from which to start reading the file
      Throws:
      com.sshtools.common.ssh.SshException
      com.sshtools.common.sftp.SftpStatusException
      TransferCancelledException
      See Also:
    • performSynchronousRead

      @Deprecated(since="3.1.0", forRemoval=true) public void performSynchronousRead(byte[] handle, int blocksize, OutputStream out, FileTransferProgress progress, long position) throws com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException, TransferCancelledException
      Deprecated, for removal: This API element is subject to removal in a future version.
      Perform a synchronous read of a file from the remote file system. This implementation waits for acknowledgement of every data packet before requesting additional data.
      Parameters:
      handle -
      blocksize -
      out -
      progress -
      position -
      Throws:
      com.sshtools.common.sftp.SftpStatusException
      com.sshtools.common.ssh.SshException
      TransferCancelledException
      See Also:
    • postReadRequest

      @Deprecated(since="3.1.0", forRemoval=true) public com.sshtools.common.util.UnsignedInteger32 postReadRequest(byte[] handle, long offset, int len) throws com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException
      Deprecated, for removal: This API element is subject to removal in a future version.
      Post a read request to the server and return the request id; this is used to optimize file downloads. In normal operation the files are transfered by using a synchronous set of requests, however this slows the download as the client has to wait for the servers response before sending another request.
      Parameters:
      handle -
      offset -
      len -
      Returns:
      UnsignedInteger32
      Throws:
      com.sshtools.common.ssh.SshException
      com.sshtools.common.sftp.SftpStatusException
      See Also:
    • readFile

      @Deprecated(since="3.1.0", forRemoval=true) public int readFile(byte[] handle, com.sshtools.common.util.UnsignedInteger64 offset, byte[] output, int off, int len) throws com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException
      Deprecated, for removal: This API element is subject to removal in a future version.
      Read a block of data from an open file.
      Parameters:
      handle - the open file handle
      offset - the offset to start reading in the file
      output - a buffer to write the returned data to
      off - the starting offset in the output buffer
      len - the length of data to read
      Returns:
      int
      Throws:
      com.sshtools.common.ssh.SshException
      com.sshtools.common.sftp.SftpStatusException
      See Also:
    • getFile

      public SftpFile getFile(String path) throws com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException
      Utility method to obtain an SftpFile instance for a given path.
      Parameters:
      path -
      Returns:
      SftpFile
      Throws:
      com.sshtools.common.sftp.SftpStatusException
      com.sshtools.common.ssh.SshException
    • getAbsolutePath

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

      @Deprecated(since="3.1.0", forRemoval=true) public void lockFile(byte[] handle, long offset, long length, int lockFlags) throws com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException
      Deprecated, for removal: This API element is subject to removal in a future version.
      Lock file.
      Parameters:
      handle -
      offset -
      length -
      lockFlags -
      Throws:
      com.sshtools.common.sftp.SftpStatusException
      com.sshtools.common.ssh.SshException
      See Also:
    • unlockFile

      @Deprecated(since="3.1.0", forRemoval=true) public void unlockFile(byte[] handle, long offset, long length) throws com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException
      Deprecated, for removal: This API element is subject to removal in a future version.
      Lock file.
      Parameters:
      handle -
      offset -
      length -
      lockFlags -
      Throws:
      com.sshtools.common.sftp.SftpStatusException
      com.sshtools.common.ssh.SshException
      See Also:
    • createSymbolicLink

      public void createSymbolicLink(String targetpath, String linkpath) throws com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException
      Create a symbolic link.
      Parameters:
      targetpath - the symbolic link to create
      linkpath - the path to which the symbolic link points
      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
    • createLink

      public void createLink(String targetpath, String linkpath, boolean symbolic) throws com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException
      Create a symbolic link.
      Parameters:
      targetpath - the symbolic link to create
      linkpath - the path to which the symbolic link points
      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
    • 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
    • getDefaultDirectory

      public String getDefaultDirectory() throws com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException
      Gets the users default directory.
      Returns:
      String
      Throws:
      com.sshtools.common.ssh.SshException
      com.sshtools.common.sftp.SftpStatusException
    • getAbsolutePath

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

      public SftpFile getSingleFileResponse(SftpMessage bar, String messageName) throws com.sshtools.common.ssh.SshException, com.sshtools.common.sftp.SftpStatusException
      Get a single SftpFile object from a message returning SSH_FXP_NAME result.
      Parameters:
      bar -
      messageName -
      Returns:
      Throws:
      com.sshtools.common.ssh.SshException
      com.sshtools.common.sftp.SftpStatusException
    • listChildren

      @Deprecated(since="3.1.0", forRemoval=true) public int listChildren(SftpFile file, List<SftpFile> children) throws com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException
      Deprecated, for removal: This API element is subject to removal in a future version.

      List the children of a directory.

      To use this method first open a directory with the openDirectory method and then create a Vector to store the results. To retrieve the results keep calling this method until it returns -1 which indicates no more results will be returned.

       SftpFile dir = sftp.openDirectory("code/foobar");
       Vector results = new Vector();
       while (sftp.listChildren(dir, results) > -1)
              ;
       sftp.closeFile(dir);
       

      Parameters:
      file -
      children -
      Returns:
      int
      Throws:
      com.sshtools.common.sftp.SftpStatusException - , SshException
      com.sshtools.common.ssh.SshException
      See Also:
    • recurseMakeDirectory

      public void recurseMakeDirectory(String path) throws com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException
      Recurse through a hierarchy of directories creating them as necessary.
      Parameters:
      path -
      Throws:
      com.sshtools.common.sftp.SftpStatusException - , SshException
      com.sshtools.common.ssh.SshException
    • openFile

      public SftpHandle openFile(String absolutePath, int flags) throws com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException
      Open a file.
      Parameters:
      absolutePath -
      flags -
      Returns:
      SftpFile
      Throws:
      com.sshtools.common.sftp.SftpStatusException - , SshException
      com.sshtools.common.ssh.SshException
    • openFile

      public SftpHandle openFile(String absolutePath, int flags, com.sshtools.common.sftp.SftpFileAttributes attrs) throws com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException
      Open a file.
      Parameters:
      absolutePath -
      flags -
      attrs -
      Returns:
      SftpFile
      Throws:
      com.sshtools.common.sftp.SftpStatusException - , SshException
      com.sshtools.common.ssh.SshException
    • openFileVersion5

      public SftpHandle openFileVersion5(String absolutePath, int flags, int accessFlags, com.sshtools.common.sftp.SftpFileAttributes attrs) 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
      Open a directory.
      Parameters:
      path -
      Returns:
      sftpfile
      Throws:
      com.sshtools.common.sftp.SftpStatusException - , SshException
      com.sshtools.common.ssh.SshException
    • closeHandle

      @Deprecated(since="3.1.0") public void closeHandle(byte[] handle) throws com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException
      Deprecated.
      Throws:
      com.sshtools.common.sftp.SftpStatusException
      com.sshtools.common.ssh.SshException
    • closeFile

      @Deprecated public void closeFile(SftpHandle file) throws IOException
      Deprecated.
      Close a file or directory.
      Parameters:
      file -
      Throws:
      com.sshtools.common.sftp.SftpStatusException - , SshException
      IOException
    • removeDirectory

      public void removeDirectory(String path) throws com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException
      Remove an empty directory.
      Parameters:
      path -
      Throws:
      com.sshtools.common.sftp.SftpStatusException - , SshException
      com.sshtools.common.ssh.SshException
    • removeFile

      public void removeFile(String filename) throws com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException
      Remove a file.
      Parameters:
      filename -
      Throws:
      com.sshtools.common.sftp.SftpStatusException - , SshException
      com.sshtools.common.ssh.SshException
    • renameFile

      public void renameFile(String oldpath, String newpath) throws com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException
      Rename an existing file.
      Parameters:
      oldpath -
      newpath -
      Throws:
      com.sshtools.common.sftp.SftpStatusException - , SshException
      com.sshtools.common.ssh.SshException
    • renameFile

      public void renameFile(String oldpath, String newpath, int flags) throws com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException
      Throws:
      com.sshtools.common.sftp.SftpStatusException
      com.sshtools.common.ssh.SshException
    • getAttributes

      public com.sshtools.common.sftp.SftpFileAttributes getAttributes(String path) throws com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException
      Get the attributes of a file. This method follows symbolic links
      Parameters:
      path -
      Returns:
      SftpFileAttributes
      Throws:
      com.sshtools.common.ssh.SshException
      com.sshtools.common.sftp.SftpStatusException
    • getLinkAttributes

      public com.sshtools.common.sftp.SftpFileAttributes getLinkAttributes(String path) throws com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException
      Get the attributes of a file. This method does not follow symbolic links so will return the attributes of an actual link, not its target.
      Parameters:
      path -
      Returns:
      Throws:
      com.sshtools.common.sftp.SftpStatusException
      com.sshtools.common.ssh.SshException
    • getAttributes

      protected com.sshtools.common.sftp.SftpFileAttributes getAttributes(String path, int messageId) throws com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException
      Throws:
      com.sshtools.common.sftp.SftpStatusException
      com.sshtools.common.ssh.SshException
    • getAttributes

      @Deprecated(since="3.1.0", forRemoval=true) public com.sshtools.common.sftp.SftpFileAttributes getAttributes(SftpFile file) throws com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException
      Deprecated, for removal: This API element is subject to removal in a future version.
      Get the attributes of a file.
      Parameters:
      file -
      Returns:
      SftpFileAttributes
      Throws:
      com.sshtools.common.sftp.SftpStatusException - , SshException
      com.sshtools.common.ssh.SshException
      See Also:
      • SftpHandle#setAttributes(byte[], SftpFileAttributes)
    • makeDirectory

      public void makeDirectory(String path) throws com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException
      Make a directory. If the directory exists this method will throw an exception.
      Parameters:
      path -
      Throws:
      com.sshtools.common.sftp.SftpStatusException - , SshException
      com.sshtools.common.ssh.SshException
    • makeDirectory

      public void makeDirectory(String path, com.sshtools.common.sftp.SftpFileAttributes attrs) throws com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException
      Make a directory. If the directory exists this method will throw an exception.
      Parameters:
      path -
      attrs -
      Throws:
      com.sshtools.common.sftp.SftpStatusException - , SshException
      com.sshtools.common.ssh.SshException
    • getExtendedReply

      public SftpMessage getExtendedReply(com.sshtools.common.util.UnsignedInteger32 requestId) throws com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException
      Throws:
      com.sshtools.common.sftp.SftpStatusException
      com.sshtools.common.ssh.SshException
    • getExtendedReply

      public SftpMessage getExtendedReply(SftpMessage bar) throws com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException
      Throws:
      com.sshtools.common.sftp.SftpStatusException
      com.sshtools.common.ssh.SshException
    • getHandleResponse

      public byte[] getHandleResponse(com.sshtools.common.util.UnsignedInteger32 requestId) throws com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException
      Throws:
      com.sshtools.common.sftp.SftpStatusException
      com.sshtools.common.ssh.SshException
    • getHandle

      public SftpHandle getHandle(com.sshtools.common.util.UnsignedInteger32 requestId, SftpFile file) throws com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException
      Throws:
      com.sshtools.common.sftp.SftpStatusException
      com.sshtools.common.ssh.SshException
    • getHandleResponse

      public byte[] getHandleResponse(SftpMessage bar) throws com.sshtools.common.sftp.SftpStatusException, com.sshtools.common.ssh.SshException
      Throws:
      com.sshtools.common.sftp.SftpStatusException
      com.sshtools.common.ssh.SshException
    • sendExtensionMessage

      public com.sshtools.common.util.UnsignedInteger32 sendExtensionMessage(String request, byte[] requestData) throws com.sshtools.common.ssh.SshException, com.sshtools.common.sftp.SftpStatusException
      Send an extension message and return the response. This is for advanced use only.
      Parameters:
      request - String
      requestData - byte[]
      Returns:
      SftpMessage
      Throws:
      com.sshtools.common.ssh.SshException
      com.sshtools.common.sftp.SftpStatusException
    • createPacket

      protected com.sshtools.common.ssh.Packet createPacket() throws IOException
      Get a packet from the available pool or create if non available
      Returns:
      Packet
      Throws:
      IOException
    • isClosed

      public boolean isClosed()
    • getMaximumLocalWindowSize

      public com.sshtools.common.util.UnsignedInteger32 getMaximumLocalWindowSize()
    • getMaximumLocalPacketLength

      public int getMaximumLocalPacketLength()
    • getMaximumRemoteWindowSize

      public com.sshtools.common.util.UnsignedInteger32 getMaximumRemoteWindowSize()
    • getMaximumRemotePacketLength

      public int getMaximumRemotePacketLength()
    • getContext

      public SshClientContext getContext()