public class DefaultSftpSessionFactory extends Object implements SessionFactory<com.jcraft.jsch.ChannelSftp.LsEntry>, SharedSessionCapable
SftpSession
instances.Constructor and Description |
---|
DefaultSftpSessionFactory() |
DefaultSftpSessionFactory(boolean isSharedSession) |
DefaultSftpSessionFactory(com.jcraft.jsch.JSch jsch,
boolean isSharedSession)
Intended for use in tests so the jsch can be mocked.
|
Modifier and Type | Method and Description |
---|---|
SftpSession |
getSession() |
boolean |
isSharedSession() |
void |
resetSharedSession()
Resets the shared session so the next
#getSession() will return a session
using a new connection. |
void |
setAllowUnknownKeys(boolean allowUnknownKeys)
When no
UserInfo 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 |
setChannelConnectTimeout(java.time.Duration timeout)
Set the connect timeout.
|
void |
setClientVersion(String clientVersion)
Allows you to set the client version property.
|
void |
setEnableDaemonThread(Boolean enableDaemonThread)
If true, all threads will be daemon threads.
|
void |
setHost(String host)
The url of the host you want connect to.
|
void |
setHostKeyAlias(String hostKeyAlias)
Sets the host key alias, used when comparing the host key to the known
hosts list.
|
void |
setKnownHosts(String knownHosts)
Deprecated.
since 5.2.5 in favor of
setKnownHostsResource(Resource) |
void |
setKnownHostsResource(Resource knownHosts)
Specifies the filename 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 |
setProxy(com.jcraft.jsch.Proxy proxy)
Allows for specifying a JSch-based
Proxy . |
void |
setServerAliveCountMax(Integer serverAliveCountMax)
Specifies the number of server-alive messages, which will be sent without
any reply from the server before disconnecting.
|
void |
setServerAliveInterval(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(Properties sessionConfig)
Using
Properties , you can set additional configuration settings on
the underlying JSch Session . |
void |
setSocketFactory(com.jcraft.jsch.SocketFactory socketFactory)
Allows you to pass in a
SocketFactory . |
void |
setTimeout(Integer timeout)
The timeout property is used as the socket timeout parameter, as well as
the default connection timeout.
|
void |
setUser(String user)
The remote user to use.
|
void |
setUserInfo(com.jcraft.jsch.UserInfo userInfo)
Provide a
UserInfo which exposes control over dealing with new keys or key
changes. |
public DefaultSftpSessionFactory()
public DefaultSftpSessionFactory(boolean isSharedSession)
isSharedSession
- true if the session is to be shared.public DefaultSftpSessionFactory(com.jcraft.jsch.JSch jsch, boolean isSharedSession)
jsch
- The jsch instance.isSharedSession
- true if the session is to be shared.public void setHost(String host)
host
- The host.JSch.getSession(String, String, int)
public void setPort(int port)
22
. If specified, this properties must
be a positive number.port
- The port.JSch.getSession(String, String, int)
public void setUser(String user)
user
- The user.JSch.getSession(String, String, int)
public void setPassword(String password)
privateKey
is
mandatory.
Not allowed if userInfo
is provided - the password is obtained
from that object.password
- The password.Session.setPassword(String)
@Deprecated public void setKnownHosts(String knownHosts)
setKnownHostsResource(Resource)
Required if allowUnknownKeys
is
false (default).
knownHosts
- The known hosts.JSch.setKnownHosts(String)
public void setKnownHostsResource(Resource knownHosts)
knownHosts
- the resource for known hosts.JSch.setKnownHosts(java.io.InputStream)
public void setPrivateKey(Resource privateKey)
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 (or userInfo
that returns a
password.privateKey
- The private key.JSch.addIdentity(String)
,
JSch.addIdentity(String, String)
public void setPrivateKeyPassphrase(String privateKeyPassphrase)
userInfo
is provided - the passphrase is obtained
from that object.privateKeyPassphrase
- The private key passphrase.JSch.addIdentity(String, String)
public void setSessionConfig(Properties sessionConfig)
Properties
, you can set additional configuration settings on
the underlying JSch Session
.sessionConfig
- The session configuration properties.Session.setConfig(Properties)
public void setProxy(com.jcraft.jsch.Proxy proxy)
Proxy
. If set, then the proxy
object is used to create the connection to the remote host.proxy
- The proxy.Session.setProxy(Proxy)
public void setSocketFactory(com.jcraft.jsch.SocketFactory socketFactory)
SocketFactory
. The socket factory is used
to create a socket to the target host. When a Proxy
is used, the
socket factory is passed to the proxy. By default plain TCP sockets are used.socketFactory
- The socket factory.Session.setSocketFactory(SocketFactory)
public void setTimeout(Integer timeout)
0
, which means,
that no timeout will occur.timeout
- The timeout.Session.setTimeout(int)
public void setClientVersion(String clientVersion)
SSH-2.0-JSCH-0.1.45
clientVersion
- The client version.Session.setClientVersion(String)
public void setHostKeyAlias(String hostKeyAlias)
hostKeyAlias
- The host key alias.Session.setHostKeyAlias(String)
public void setServerAliveInterval(Integer serverAliveInterval)
serverAliveInterval
- The server alive interval.Session.setServerAliveInterval(int)
public void setServerAliveCountMax(Integer serverAliveCountMax)
1
.serverAliveCountMax
- The server alive count max.Session.setServerAliveCountMax(int)
public void setEnableDaemonThread(Boolean enableDaemonThread)
false
,
normal non-daemon threads will be used. This property will be set on the
underlying Session
using
Session.setDaemonThread(boolean)
. There, this
property will default to false
, if not explicitly set.enableDaemonThread
- true to enable a daemon thread.Session.setDaemonThread(boolean)
public void setUserInfo(com.jcraft.jsch.UserInfo userInfo)
UserInfo
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 (see setKnownHostsResource(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 by
allowUnknownKeys
.
If setPassword
is invoked with a non-null password, it will
override any password in the supplied UserInfo
.
NOTE: When this is provided, the password
and
passphrase
are not allowed because those values
will be obtained from the UserInfo
.
userInfo
- the UserInfo.Session.setUserInfo(com.jcraft.jsch.UserInfo)
public void setAllowUnknownKeys(boolean allowUnknownKeys)
UserInfo
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.allowUnknownKeys
- true to allow connecting to unknown hosts.public void setChannelConnectTimeout(java.time.Duration timeout)
timeout
- the timeout to set.public SftpSession getSession()
getSession
in interface SessionFactory<com.jcraft.jsch.ChannelSftp.LsEntry>
public final boolean isSharedSession()
isSharedSession
in interface SharedSessionCapable
public void resetSharedSession()
SharedSessionCapable
#getSession()
will return a session
using a new connection.resetSharedSession
in interface SharedSessionCapable