Class SftpClient.SftpClientBuilder

java.lang.Object
com.sshtools.client.sftp.SftpClient.SftpClientBuilder
Enclosing class:
SftpClient

public static final class SftpClient.SftpClientBuilder extends Object
  • Constructor Details

    • SftpClientBuilder

      public SftpClientBuilder()
  • Method Details

    • create

      public static SftpClient.SftpClientBuilder create()
      Returns:
      builder
    • withCustomRoots

      public SftpClient.SftpClientBuilder withCustomRoots(String... rootPaths)
      Adds one or more custom file system root paths. Some devices have unusual file system roots such as "flash:", customRoots contains these. If a device uses roots like this, and folder traversal on the device is required then it must have its root stored in customRoots
      Parameters:
      rootPaths - root paths
      See Also:
      • SftpClientBuilder#withCustomRoots(String)
    • withConnection

      public SftpClient.SftpClientBuilder withConnection(com.sshtools.common.ssh.SshConnection connection)
      Use an existing SshConnection to create the SftpClient.
      Parameters:
      connection - connection
      Returns:
      this for chaining
    • withClient

      public SftpClient.SftpClientBuilder withClient(SshClient client)
      Use an existing SshClient to create the SftpClient.
      Parameters:
      client - client
      Returns:
      this for chaining
    • withFileFactory

      public SftpClient.SftpClientBuilder withFileFactory(com.sshtools.common.files.AbstractFileFactory<?> fileFactory)
      Use a specific AbstractFileFactory for this client.
      Parameters:
      factory - factory
      Returns:
      this for chaining
    • withLocalHomeSandbox

      public SftpClient.SftpClientBuilder withLocalHomeSandbox(boolean localHomeSandbox)
      Whether or not to sandbox the path provided as the Local Home/code>. default this is true. Will only be used when withLocalHome(Path) or withLocalHome(File) have been used, and withFileFactory(AbstractFileFactory) has not been used.
    • withWithoutLocalHomeSandbox

      public SftpClient.SftpClientBuilder withWithoutLocalHomeSandbox()
      Set to not sandbox the path provided as the Local Home/code>. default this is true. Will only be used when withLocalHome(Path) or withLocalHome(File) have been used, and withFileFactory(AbstractFileFactory) has not been used.
    • withRemotePath

      public SftpClient.SftpClientBuilder withRemotePath(String remotePath)
      Start off in a specified remote path. Any subsequent relative remote paths would then be resolved against this path. The path may be changed at runtime using SftpClient.cd(String).
      Parameters:
      path - path
      Returns:
      this for chaining
    • withLocalPath

      public SftpClient.SftpClientBuilder withLocalPath(String localPath)
      Start off in a specified local path. Any subsequent relative remote paths would then be resolved against this path. The path may be changed at runtime using SftpClient.lcd(String).
      Parameters:
      path - path
      Returns:
      this for chaining
    • withLocalHome

      public SftpClient.SftpClientBuilder withLocalHome(Path localHome)
      Use a specific Path as the home of the local file system. Will only be used if withFileFactory(AbstractFileFactory) has not been used. If not provided, the current user's home directory (i.e. System.getProperty("user.home");) will be used.

      Use of this method will replace the currently configured AbstractFileFactory if any.

      Parameters:
      localHome - local root path
      Returns:
      this for chaining
    • withLocalHome

      public SftpClient.SftpClientBuilder withLocalHome(File localRoot)
      Use a specific Path as the home of the local file system. Will only be used if withFileFactory(AbstractFileFactory) has not been used. If not provided, the current user's home directory (i.e. System.getProperty("user.home");) will be used.

      Use of this method will replace the currently configured AbstractFileFactory if any.

      Parameters:
      localRoot - local root path
      Returns:
      this for chaining
    • withBlockSize

      public SftpClient.SftpClientBuilder withBlockSize(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
    • withBufferSize

      public SftpClient.SftpClientBuilder withBufferSize(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 - buffer size
    • withAsyncRequests

      public SftpClient.SftpClientBuilder withAsyncRequests(int asyncRequests)
      Set the maximum number of asynchronous requests to use for optimised reads and writes to remote files. When not provided, this will be calculate from the remote window size and the block size.
      Parameters:
      asyncRequests - max async requests
    • build

      public SftpClient build() throws com.sshtools.common.ssh.SshException, com.sshtools.common.permissions.PermissionDeniedException, IOException
      Build a new SftpClient.
      Returns:
      sftp client
      Throws:
      com.sshtools.common.ssh.SshException - on SSH error
      IOException - on I/O error
      com.sshtools.common.permissions.PermissionDeniedException - on permissions error