Class SftpConfig

java.lang.Object
org.kiwiproject.jsch.SftpConfig

public class SftpConfig extends Object
This (Dropwizard) config class allows for common configuration for SFTP access to remote hosts.

One note on the password and privateKeyFilePath fields: the SFTP connector will use either the password or the private key but not both. If both are specified, the private key will take precedence. This allows for the greatest flexibility when connecting to different SFTP locations.

Implementation Note:
This uses Dropwizard's Duration and several Dropwizard validation annotations in addition to the standard Java Beans Validation annotations, so you will need to ensure the appropriate Dropwizard JAR files are on the class/module path.
  • Constructor Details

    • SftpConfig

      @ConstructorProperties({"port","host","user","password","privateKeyFilePath","preferredAuthentications","remoteBasePath","errorPath","knownHostsFile","disableStrictHostChecking","timeout"}) public SftpConfig(int port, String host, String user, String password, String privateKeyFilePath, String preferredAuthentications, String remoteBasePath, String errorPath, String knownHostsFile, boolean disableStrictHostChecking, io.dropwizard.util.Duration timeout)
      All-args constructor.
      Parameters:
      port - the remote port
      host - the remote host
      user - the SFTP username
      password - the SFTP password
      privateKeyFilePath - path to private key file
      preferredAuthentications - comma-separated list of authentications to attempt
      remoteBasePath - root directory of the remote SFTP location
      errorPath - local directory to write out any errors if SFTP fails
      knownHostsFile - path to the known hosts file
      disableStrictHostChecking - if true, we will set StrictHostKeyChecking=no
      timeout - the SFTP connection timeout
      Implementation Note:
      This is intentionally not using Lombok because using AllArgsConstructor together with @Builder results in an all-args constructor that does not respect Builder.Default. As a result we need to handle the defaults ourselves. This is intended to be used during deserialization from an external configuration file (e.g. a Dropwizard YAML configuration file, or from JSON). Prefer the builder when constructing programmatically.
    • SftpConfig

      public SftpConfig()
  • Method Details

    • builder

      public static SftpConfig.SftpConfigBuilder builder()
    • getPort

      public int getPort()
      The SFTP port. Default is 22.
    • getHost

      public String getHost()
      The remote host to connect to via SFTP.
    • getUser

      public String getUser()
      The remote user to connect with via SFTP.
    • getPassword

      public String getPassword()
      The password, only used if password authentication is used.
    • getPrivateKeyFilePath

      public String getPrivateKeyFilePath()
      The path to the private key file, only used if public key authentication is used.
    • getPreferredAuthentications

      public String getPreferredAuthentications()
      The comma-separated list of preferred authentication mechanisms. Equivalent to the -o PreferredAuthentications=[gssapi-with-mic|hostbased|publickey|keyboard-interactive|password] option.

      The default is publickey,password which differs from the default order in the SFTP command. See the ssh_info man page for details.

    • getRemoteBasePath

      public String getRemoteBasePath()
      The root directory of the remote SFTP location, provided as a convenience to store the remote path in the same place as the other SFTP properties.

      It is not required nor currently used by SftpConnector or SftpTransfers.

    • getErrorPath

      public String getErrorPath()
      The local directory to write out any errors if SFTP fails.
    • getKnownHostsFile

      public String getKnownHostsFile()
      The path to the known hosts file.
    • isDisableStrictHostChecking

      public boolean isDisableStrictHostChecking()
      Provides option to disable strict host key checking, equivalent to the -o StrictHostKeyChecking=[yes|no] option.

      The default is false. See the ssh_info man page for more details.

    • getTimeout

      public io.dropwizard.util.Duration getTimeout()
      SFTP connection timeout. Default is 5 seconds.
      Implementation Note:
      The minimum duration annotation of 50 milliseconds is somewhat arbitrary, and is really just intended to ensure a positive value.
    • setPort

      public void setPort(int port)
      The SFTP port. Default is 22.
    • setHost

      public void setHost(String host)
      The remote host to connect to via SFTP.
    • setUser

      public void setUser(String user)
      The remote user to connect with via SFTP.
    • setPassword

      public void setPassword(String password)
      The password, only used if password authentication is used.
    • setPrivateKeyFilePath

      public void setPrivateKeyFilePath(String privateKeyFilePath)
      The path to the private key file, only used if public key authentication is used.
    • setPreferredAuthentications

      public void setPreferredAuthentications(String preferredAuthentications)
      The comma-separated list of preferred authentication mechanisms. Equivalent to the -o PreferredAuthentications=[gssapi-with-mic|hostbased|publickey|keyboard-interactive|password] option.

      The default is publickey,password which differs from the default order in the SFTP command. See the ssh_info man page for details.

    • setRemoteBasePath

      public void setRemoteBasePath(String remoteBasePath)
      The root directory of the remote SFTP location, provided as a convenience to store the remote path in the same place as the other SFTP properties.

      It is not required nor currently used by SftpConnector or SftpTransfers.

    • setErrorPath

      public void setErrorPath(String errorPath)
      The local directory to write out any errors if SFTP fails.
    • setKnownHostsFile

      public void setKnownHostsFile(String knownHostsFile)
      The path to the known hosts file.
    • setDisableStrictHostChecking

      public void setDisableStrictHostChecking(boolean disableStrictHostChecking)
      Provides option to disable strict host key checking, equivalent to the -o StrictHostKeyChecking=[yes|no] option.

      The default is false. See the ssh_info man page for more details.

    • setTimeout

      public void setTimeout(io.dropwizard.util.Duration timeout)
      SFTP connection timeout. Default is 5 seconds.
      Implementation Note:
      The minimum duration annotation of 50 milliseconds is somewhat arbitrary, and is really just intended to ensure a positive value.