Class DefaultSftpSessionFactory

java.lang.Object
org.springframework.integration.sftp.session.DefaultSftpSessionFactory
All Implemented Interfaces:
DisposableBean, SessionFactory<org.apache.sshd.sftp.client.SftpClient.DirEntry>, SharedSessionCapable

public class DefaultSftpSessionFactory extends Object implements SessionFactory<org.apache.sshd.sftp.client.SftpClient.DirEntry>, SharedSessionCapable, DisposableBean
Factory for creating SftpSession instances.

The createSftpClient(ClientSession, SftpVersionSelector, SftpErrorDataHandler) can be overridden to provide a custom SftpClient. The DefaultSftpSessionFactory.ConcurrentSftpClient is used by default.

Since:
2.0
Author:
Josh Long, Mario Gray, Oleg Zhurakousky, Gunnar Hillert, Gary Russell, David Liu, Pat Turner, Artem Bilan, Krzysztof Debski, Auke Zaaiman, Christian Tzolov, Adama Sorho, Darryl Smith
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    protected class 
    The DefaultSftpClient extension to lock the DefaultSftpClient.send(int, Buffer) for concurrent interaction.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
    DefaultSftpSessionFactory(boolean isSharedSession)
     
    DefaultSftpSessionFactory(org.apache.sshd.client.SshClient sshClient, boolean isSharedSession)
    Instantiate based on the provided SshClient, e.g.
  • Method Summary

    Modifier and Type
    Method
    Description
    protected org.apache.sshd.sftp.client.SftpClient
    createSftpClient(org.apache.sshd.client.session.ClientSession clientSession, org.apache.sshd.sftp.client.SftpVersionSelector initialVersionSelector, org.apache.sshd.sftp.client.SftpErrorDataHandler errorDataHandler)
    Can be overridden to provide a custom SftpClient to getSession().
    void
     
     
    final boolean
     
    void
    Resets the shared session so the next #getSession() will return a session using a new connection.
    void
    setAllowUnknownKeys(boolean allowUnknownKeys)
    When no knownHosts has been provided, set to true to unconditionally allow connecting to an unknown host or when a host's key has changed (see knownHosts).
    void
    The url of the host you want to connect to.
    void
    setHostConfig(org.apache.sshd.client.config.hosts.HostConfigEntry hostConfig)
    Provide a HostConfigEntry as an alternative for the user/host/port options.
    void
    Specifies a Resource that will be used for a host key repository.
    void
    setPassword(String password)
    The password to authenticate against the remote host.
    void
    setPort(int port)
    The port over which the SFTP connection shall be established.
    void
    setPrivateKey(Resource privateKey)
    Allows you to set a Resource, which represents the location of the private key used for authenticating against the remote host.
    void
    setPrivateKeyPassphrase(String privateKeyPassphrase)
    The password for the private key.
    void
    setSftpVersionSelector(org.apache.sshd.sftp.client.SftpVersionSelector sftpVersionSelector)
     
    void
    setSshClientConfigurer(Consumer<org.apache.sshd.client.SshClient> sshClientConfigurer)
    Set a Consumer as a callback to further customize an internal SshClient instance.
    void
    The timeout property is used as the socket timeout parameter, as well as the default connection timeout.
    void
    The remote user to use.
    void
    setUserInteraction(org.apache.sshd.client.auth.keyboard.UserInteraction userInteraction)
    Provide a UserInteraction which exposes control over dealing with new keys or key changes.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • DefaultSftpSessionFactory

      public DefaultSftpSessionFactory()
    • DefaultSftpSessionFactory

      public DefaultSftpSessionFactory(boolean isSharedSession)
      Parameters:
      isSharedSession - true if the session is to be shared.
    • DefaultSftpSessionFactory

      public DefaultSftpSessionFactory(org.apache.sshd.client.SshClient sshClient, boolean isSharedSession)
      Instantiate based on the provided SshClient, e.g. some extension for HTTP/SOCKS.
      Parameters:
      sshClient - the SshClient instance.
      isSharedSession - true if the session is to be shared.
  • Method Details

    • setHost

      public void setHost(String host)
      The url of the host you want to connect to. This is a mandatory property.
      Parameters:
      host - The host.
      See Also:
      • ClientSessionCreator.connect(String, String, int)
    • setPort

      public void setPort(int port)
      The port over which the SFTP connection shall be established. If not specified, this value defaults to 22. If specified, this properties must be a positive number.
      Parameters:
      port - The port.
      See Also:
      • ClientSessionCreator.connect(String, String, int)
    • setUser

      public void setUser(String user)
      The remote user to use. This is a mandatory property.
      Parameters:
      user - The user.
      See Also:
      • ClientSessionCreator.connect(String, String, int)
    • setPassword

      public void setPassword(String password)
      The password to authenticate against the remote host. If a password is not provided, then a privateKey is mandatory.
      Parameters:
      password - The password.
      See Also:
      • SshClient.setPasswordIdentityProvider(PasswordIdentityProvider)
    • setHostConfig

      public void setHostConfig(org.apache.sshd.client.config.hosts.HostConfigEntry hostConfig)
      Provide a HostConfigEntry as an alternative for the user/host/port options. Can be configured with a proxy jump property.
      Parameters:
      hostConfig - the HostConfigEntry for connection.
      Since:
      6.0
      See Also:
      • ClientSessionCreator.connect(HostConfigEntry)
    • setKnownHostsResource

      public void setKnownHostsResource(Resource knownHosts)
      Specifies a Resource that will be used for a host key repository. The data has to have the same format as OpenSSH's known_hosts file.
      Parameters:
      knownHosts - the resource for known hosts.
      Since:
      5.2.5
      See Also:
      • SshClient.setServerKeyVerifier(ServerKeyVerifier)
    • setPrivateKey

      public void setPrivateKey(Resource privateKey)
      Allows you to set a Resource, which represents the location of the private key used for authenticating against the remote host. If the privateKey is not provided, then the password property is mandatory.
      Parameters:
      privateKey - The private key.
      See Also:
      • SshClient.setKeyIdentityProvider(KeyIdentityProvider)
    • setPrivateKeyPassphrase

      public void setPrivateKeyPassphrase(String privateKeyPassphrase)
      The password for the private key. Optional.
      Parameters:
      privateKeyPassphrase - The private key passphrase.
      See Also:
      • SshClient.setKeyIdentityProvider(KeyIdentityProvider)
    • setUserInteraction

      public void setUserInteraction(org.apache.sshd.client.auth.keyboard.UserInteraction userInteraction)
      Provide a UserInteraction which exposes control over dealing with new keys or key changes. As Spring Integration will not normally allow user interaction, the implementation must respond to SSH protocol calls in a suitable way.
      Parameters:
      userInteraction - the UserInteraction.
      Since:
      4.1.7
      See Also:
      • SshClient.setUserInteraction(UserInteraction)
    • setAllowUnknownKeys

      public void setAllowUnknownKeys(boolean allowUnknownKeys)
      When no knownHosts has been provided, set to true to unconditionally allow connecting to an unknown host or when a host's key has changed (see knownHosts). Default false (since 4.2). Set to true if a knownHosts file is not provided.
      Parameters:
      allowUnknownKeys - true to allow connecting to unknown hosts.
      Since:
      4.1.7
    • setTimeout

      public void setTimeout(Integer timeout)
      The timeout property is used as the socket timeout parameter, as well as the default connection timeout. Defaults to 30 seconds. Setting to 0 means no timeout; to null - infinite wait.
      Parameters:
      timeout - the timeout.
      See Also:
      • VerifiableFuture.verify(Duration, org.apache.sshd.common.future.CancelOption...)
    • setSftpVersionSelector

      public void setSftpVersionSelector(org.apache.sshd.sftp.client.SftpVersionSelector sftpVersionSelector)
    • setSshClientConfigurer

      public void setSshClientConfigurer(Consumer<org.apache.sshd.client.SshClient> sshClientConfigurer)
      Set a Consumer as a callback to further customize an internal SshClient instance. For example, to set custom values for its properties using PropertyResolverUtils.updateProperty(org.apache.sshd.common.PropertyResolver, java.lang.String, long) API.
      Parameters:
      sshClientConfigurer - the Consumer to configure an internal SshClient instance.
      Since:
      6.4
      See Also:
      • SshClient
      • PropertyResolverUtils.updateProperty(org.apache.sshd.common.PropertyResolver, java.lang.String, long)
    • getSession

      public SftpSession getSession()
      Specified by:
      getSession in interface SessionFactory<org.apache.sshd.sftp.client.SftpClient.DirEntry>
    • isSharedSession

      public final boolean isSharedSession()
      Specified by:
      isSharedSession in interface SharedSessionCapable
      Returns:
      true if this factory uses a shared session.
    • resetSharedSession

      public void resetSharedSession()
      Description copied from interface: SharedSessionCapable
      Resets the shared session so the next #getSession() will return a session using a new connection.
      Specified by:
      resetSharedSession in interface SharedSessionCapable
    • createSftpClient

      protected org.apache.sshd.sftp.client.SftpClient createSftpClient(org.apache.sshd.client.session.ClientSession clientSession, org.apache.sshd.sftp.client.SftpVersionSelector initialVersionSelector, org.apache.sshd.sftp.client.SftpErrorDataHandler errorDataHandler) throws IOException
      Can be overridden to provide a custom SftpClient to getSession().
      Parameters:
      clientSession - the ClientSession
      initialVersionSelector - the initial SftpVersionSelector
      errorDataHandler - the SftpErrorDataHandler to handle incoming data through the error stream.
      Returns:
      SftpClient
      Throws:
      IOException - if failed to initialize
      Since:
      6.1.3
    • destroy

      public void destroy()
      Specified by:
      destroy in interface DisposableBean