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 ClassesModifier and TypeClassDescriptionprotected classTheDefaultSftpClientextension to lock theDefaultSftpClient.send(int, Buffer)for concurrent interaction. -
Constructor Summary
ConstructorsConstructorDescriptionDefaultSftpSessionFactory(boolean isSharedSession) DefaultSftpSessionFactory(org.apache.sshd.client.SshClient sshClient, boolean isSharedSession) Instantiate based on the providedSshClient, e.g. -
Method Summary
Modifier and TypeMethodDescriptionprotected org.apache.sshd.sftp.client.SftpClientcreateSftpClient(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 customSftpClienttogetSession().voiddestroy()final booleanvoidResets the shared session so the next#getSession()will return a session using a new connection.voidsetAllowUnknownKeys(boolean allowUnknownKeys) When noknownHostshas been provided, set to true to unconditionally allow connecting to an unknown host or when a host's key has changed (seeknownHosts).voidThe url of the host you want to connect to.voidsetHostConfig(org.apache.sshd.client.config.hosts.HostConfigEntry hostConfig) Provide aHostConfigEntryas an alternative for the user/host/port options.voidsetKnownHostsResource(Resource knownHosts) Specifies aResourcethat will be used for a host key repository.voidsetPassword(String password) The password to authenticate against the remote host.voidsetPort(int port) The port over which the SFTP connection shall be established.voidsetPrivateKey(Resource privateKey) Allows you to set aResource, which represents the location of the private key used for authenticating against the remote host.voidsetPrivateKeyPassphrase(String privateKeyPassphrase) The password for the private key.voidsetSftpVersionSelector(org.apache.sshd.sftp.client.SftpVersionSelector sftpVersionSelector) voidsetSshClientConfigurer(Consumer<org.apache.sshd.client.SshClient> sshClientConfigurer) Set aConsumeras a callback to further customize an internalSshClientinstance.voidsetTimeout(Integer timeout) The timeout property is used as the socket timeout parameter, as well as the default connection timeout.voidThe remote user to use.voidsetUserInteraction(org.apache.sshd.client.auth.keyboard.UserInteraction userInteraction) Provide aUserInteractionwhich exposes control over dealing with new keys or key changes.
-
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 providedSshClient, e.g. some extension for HTTP/SOCKS.- Parameters:
sshClient- theSshClientinstance.isSharedSession- true if the session is to be shared.
-
-
Method Details
-
setHost
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 to22. If specified, this properties must be a positive number.- Parameters:
port- The port.- See Also:
-
ClientSessionCreator.connect(String, String, int)
-
setUser
The remote user to use. This is a mandatory property.- Parameters:
user- The user.- See Also:
-
ClientSessionCreator.connect(String, String, int)
-
setPassword
The password to authenticate against the remote host. If a password is not provided, then aprivateKeyis mandatory.- Parameters:
password- The password.- See Also:
-
SshClient.setPasswordIdentityProvider(PasswordIdentityProvider)
-
setHostConfig
public void setHostConfig(org.apache.sshd.client.config.hosts.HostConfigEntry hostConfig) Provide aHostConfigEntryas an alternative for the user/host/port options. Can be configured with a proxy jump property.- Parameters:
hostConfig- theHostConfigEntryfor connection.- Since:
- 6.0
- See Also:
-
ClientSessionCreator.connect(HostConfigEntry)
-
setKnownHostsResource
Specifies aResourcethat 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
Allows you to set aResource, which represents the location of the private key used for authenticating against the remote host. If the privateKey is not provided, then thepasswordproperty is mandatory.- Parameters:
privateKey- The private key.- See Also:
-
SshClient.setKeyIdentityProvider(KeyIdentityProvider)
-
setPrivateKeyPassphrase
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 aUserInteractionwhich 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 noknownHostshas been provided, set to true to unconditionally allow connecting to an unknown host or when a host's key has changed (seeknownHosts). 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
The timeout property is used as the socket timeout parameter, as well as the default connection timeout. Defaults to30 seconds. Setting to0means no timeout; tonull- 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
Set aConsumeras a callback to further customize an internalSshClientinstance. For example, to set custom values for its properties usingPropertyResolverUtils.updateProperty(org.apache.sshd.common.PropertyResolver, java.lang.String, long)API.- Parameters:
sshClientConfigurer- theConsumerto configure an internalSshClientinstance.- Since:
- 6.4
- See Also:
-
SshClientPropertyResolverUtils.updateProperty(org.apache.sshd.common.PropertyResolver, java.lang.String, long)
-
getSession
- Specified by:
getSessionin interfaceSessionFactory<org.apache.sshd.sftp.client.SftpClient.DirEntry>
-
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 customSftpClienttogetSession().- Parameters:
clientSession- theClientSessioninitialVersionSelector- the initialSftpVersionSelectorerrorDataHandler- theSftpErrorDataHandlerto 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:
destroyin interfaceDisposableBean
-