Class DefaultSftpSessionFactory
java.lang.Object
org.springframework.integration.sftp.session.DefaultSftpSessionFactory
- All Implemented Interfaces:
org.springframework.integration.file.remote.session.SessionFactory<com.jcraft.jsch.ChannelSftp.LsEntry>
,org.springframework.integration.file.remote.session.SharedSessionCapable
public class DefaultSftpSessionFactory
extends java.lang.Object
implements org.springframework.integration.file.remote.session.SessionFactory<com.jcraft.jsch.ChannelSftp.LsEntry>, org.springframework.integration.file.remote.session.SharedSessionCapable
Factory for creating
SftpSession
instances.- Since:
- 2.0
-
Constructor Summary
Constructors Constructor Description DefaultSftpSessionFactory()
DefaultSftpSessionFactory(boolean isSharedSession)
DefaultSftpSessionFactory(com.jcraft.jsch.JSch jsch, boolean isSharedSession)
Intended for use in tests so the jsch can be mocked. -
Method Summary
Modifier and Type Method Description SftpSession
getSession()
boolean
isSharedSession()
void
resetSharedSession()
void
setAllowUnknownKeys(boolean allowUnknownKeys)
When noUserInfo
has been provided, set to true to unconditionally allow connecting to an unknown host or when a host's key has changed (seeknownHosts
).void
setChannelConnectTimeout(java.time.Duration timeout)
Set the connection timeout.void
setClientVersion(java.lang.String clientVersion)
Allows you to set the client version property.void
setEnableDaemonThread(java.lang.Boolean enableDaemonThread)
If true, all threads will be daemon threads.void
setHost(java.lang.String host)
The url of the host you want connect to.void
setHostKeyAlias(java.lang.String hostKeyAlias)
Sets the host key alias, used when comparing the host key to the known hosts list.void
setKnownHosts(java.lang.String knownHosts)
Deprecated.since 5.2.5 in favor ofsetKnownHostsResource(Resource)
void
setKnownHostsResource(org.springframework.core.io.Resource knownHosts)
Specifies the filename that will be used for a host key repository.void
setPassword(java.lang.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(org.springframework.core.io.Resource privateKey)
Allows you to set aResource
, which represents the location of the private key used for authenticating against the remote host.void
setPrivateKeyPassphrase(java.lang.String privateKeyPassphrase)
The password for the private key.void
setProxy(com.jcraft.jsch.Proxy proxy)
Allows for specifying a JSch-basedProxy
.void
setServerAliveCountMax(java.lang.Integer serverAliveCountMax)
Specifies the number of server-alive messages, which will be sent without any reply from the server before disconnecting.void
setServerAliveInterval(java.lang.Integer serverAliveInterval)
Sets the timeout interval (milliseconds) before a server alive message is sent, in case no message is received from the server.void
setSessionConfig(java.util.Properties sessionConfig)
UsingProperties
, you can set additional configuration settings on the underlying JSchSession
.void
setSocketFactory(com.jcraft.jsch.SocketFactory socketFactory)
Allows you to pass in aSocketFactory
.void
setTimeout(java.lang.Integer timeout)
The timeout property is used as the socket timeout parameter, as well as the default connection timeout.void
setUser(java.lang.String user)
The remote user to use.void
setUserInfo(com.jcraft.jsch.UserInfo userInfo)
Provide aUserInfo
which 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(com.jcraft.jsch.JSch jsch, boolean isSharedSession)Intended for use in tests so the jsch can be mocked.- Parameters:
jsch
- The jsch instance.isSharedSession
- true if the session is to be shared.
-
-
Method Details
-
setHost
public void setHost(java.lang.String host)The url of the host you want connect to. This is a mandatory property.- Parameters:
host
- The host.- See Also:
JSch.getSession(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:
JSch.getSession(String, String, int)
-
setUser
public void setUser(java.lang.String user)The remote user to use. This is a mandatory property.- Parameters:
user
- The user.- See Also:
JSch.getSession(String, String, int)
-
setPassword
public void setPassword(java.lang.String password)The password to authenticate against the remote host. If a password is not provided, then aprivateKey
is mandatory. Not allowed ifuserInfo
is provided - the password is obtained from that object.- Parameters:
password
- The password.- See Also:
Session.setPassword(String)
-
setKnownHosts
@Deprecated public void setKnownHosts(java.lang.String knownHosts)Deprecated.since 5.2.5 in favor ofsetKnownHostsResource(Resource)
Specifies the filename that will be used for a host key repository. The file has the same format as OpenSSH's known_hosts file.Required if
allowUnknownKeys
is false (default).- Parameters:
knownHosts
- The known hosts.- See Also:
JSch.setKnownHosts(String)
-
setKnownHostsResource
public void setKnownHostsResource(org.springframework.core.io.Resource knownHosts)Specifies the filename that will be used for a host key repository. The file has the same format as OpenSSH's known_hosts file.- Parameters:
knownHosts
- the resource for known hosts.- Since:
- 5.2.5
- See Also:
JSch.setKnownHosts(java.io.InputStream)
-
setPrivateKey
public void setPrivateKey(org.springframework.core.io.Resource privateKey)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 thepassword
property is mandatory (oruserInfo
that returns a password.- Parameters:
privateKey
- The private key.- See Also:
JSch.addIdentity(String)
,JSch.addIdentity(String, String)
-
setPrivateKeyPassphrase
public void setPrivateKeyPassphrase(java.lang.String privateKeyPassphrase)The password for the private key. Optional. Not allowed ifuserInfo
is provided - the passphrase is obtained from that object.- Parameters:
privateKeyPassphrase
- The private key passphrase.- See Also:
JSch.addIdentity(String, String)
-
setSessionConfig
public void setSessionConfig(java.util.Properties sessionConfig)UsingProperties
, you can set additional configuration settings on the underlying JSchSession
.- Parameters:
sessionConfig
- The session configuration properties.- See Also:
Session.setConfig(Properties)
-
setProxy
public void setProxy(com.jcraft.jsch.Proxy proxy)Allows for specifying a JSch-basedProxy
. If set, then the proxy object is used to create the connection to the remote host.- Parameters:
proxy
- The proxy.- See Also:
Session.setProxy(Proxy)
-
setSocketFactory
public void setSocketFactory(com.jcraft.jsch.SocketFactory socketFactory)Allows you to pass in aSocketFactory
. The socket factory is used to create a socket to the target host. When aProxy
is used, the socket factory is passed to the proxy. By default plain TCP sockets are used.- Parameters:
socketFactory
- The socket factory.- See Also:
Session.setSocketFactory(SocketFactory)
-
setTimeout
public void setTimeout(java.lang.Integer timeout)The timeout property is used as the socket timeout parameter, as well as the default connection timeout. Defaults to0
, which means, that no timeout will occur.- Parameters:
timeout
- The timeout.- See Also:
Session.setTimeout(int)
-
setClientVersion
public void setClientVersion(java.lang.String clientVersion)Allows you to set the client version property. It's default depends on the underlying JSch version but it will look likeSSH-2.0-JSCH-0.1.45
- Parameters:
clientVersion
- The client version.- See Also:
Session.setClientVersion(String)
-
setHostKeyAlias
public void setHostKeyAlias(java.lang.String hostKeyAlias)Sets the host key alias, used when comparing the host key to the known hosts list.- Parameters:
hostKeyAlias
- The host key alias.- See Also:
Session.setHostKeyAlias(String)
-
setServerAliveInterval
public void setServerAliveInterval(java.lang.Integer serverAliveInterval)Sets the timeout interval (milliseconds) before a server alive message is sent, in case no message is received from the server.- Parameters:
serverAliveInterval
- The server alive interval.- See Also:
Session.setServerAliveInterval(int)
-
setServerAliveCountMax
public void setServerAliveCountMax(java.lang.Integer serverAliveCountMax)Specifies the number of server-alive messages, which will be sent without any reply from the server before disconnecting. If not set, this property defaults to1
.- Parameters:
serverAliveCountMax
- The server alive count max.- See Also:
Session.setServerAliveCountMax(int)
-
setEnableDaemonThread
public void setEnableDaemonThread(java.lang.Boolean enableDaemonThread)If true, all threads will be daemon threads. If set tofalse
, normal non-daemon threads will be used. This property will be set on the underlyingSession
usingSession.setDaemonThread(boolean)
. There, this property will default tofalse
, if not explicitly set.- Parameters:
enableDaemonThread
- true to enable a daemon thread.- See Also:
Session.setDaemonThread(boolean)
-
setUserInfo
public void setUserInfo(com.jcraft.jsch.UserInfo userInfo)Provide aUserInfo
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 Jsch calls in a suitable way.Jsch calls
UserInfo.promptYesNo(String)
when connecting to an unknown host, or when a known host's key has changed (seesetKnownHostsResource(Resource)
knownHosts}). Generally, it should return false as returning true will accept all new keys or key changes.If no
UserInfo
is provided, the behavior is defined byallowUnknownKeys
.If
setPassword
is invoked with a non-null password, it will override any password in the suppliedUserInfo
.NOTE: When this is provided, the
password
andpassphrase
are not allowed because those values will be obtained from theUserInfo
.- Parameters:
userInfo
- the UserInfo.- Since:
- 4.1.7
- See Also:
Session.setUserInfo(com.jcraft.jsch.UserInfo)
-
setAllowUnknownKeys
public void setAllowUnknownKeys(boolean allowUnknownKeys)When noUserInfo
has 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
-
setChannelConnectTimeout
public void setChannelConnectTimeout(java.time.Duration timeout)Set the connection timeout.- Parameters:
timeout
- the timeout to set.- Since:
- 5.2
-
getSession
- Specified by:
getSession
in interfaceorg.springframework.integration.file.remote.session.SessionFactory<com.jcraft.jsch.ChannelSftp.LsEntry>
-
isSharedSession
public final boolean isSharedSession()- Specified by:
isSharedSession
in interfaceorg.springframework.integration.file.remote.session.SharedSessionCapable
-
resetSharedSession
public void resetSharedSession()- Specified by:
resetSharedSession
in interfaceorg.springframework.integration.file.remote.session.SharedSessionCapable
-