Package org.apache.sshd.client
Class SshClient
- java.lang.Object
-
- All Implemented Interfaces:
Closeable
,AutoCloseable
,Channel
,ClientAuthenticationManager
,ClientFactoryManager
,ClientIdentityLoaderHolder
,ClientIdentityLoaderManager
,ClientProxyConnectorHolder
,ClientSessionCreator
,AttributeRepository
,AttributeStore
,UserAuthFactoriesManager<ClientSession,UserAuth,UserAuthFactory>
,ChannelListenerManager
,ChannelStreamPacketWriterResolver
,ChannelStreamPacketWriterResolverManager
,Closeable
,FilePasswordProviderHolder
,FilePasswordProviderManager
,FactoryManager
,PortForwardingEventListenerManager
,IoServiceEventListenerManager
,KexExtensionHandlerManager
,KexFactoryManager
,KeyIdentityProviderHolder
,PropertyResolver
,ReservedSessionMessagesManager
,SessionDisconnectHandlerManager
,SessionHeartbeatController
,SessionListenerManager
,UnknownChannelReferenceHandlerManager
,SignatureFactoriesManager
public class SshClient extends AbstractFactoryManager implements ClientFactoryManager, ClientSessionCreator, Closeable
Entry point for the client side of the SSH protocol.
The default configured client can be created using the
setUpDefaultClient()
. The next step is to configure and then start the client using thestart()
method.Sessions can then be created using on of the
ClientSessionCreator.connect(String, String, int)
orClientSessionCreator.connect(String, java.net.SocketAddress)
methods.The client can be stopped any time using the
stop()
method.Following is an example of using the
SshClient
:
Note: the idea is to have onetry (SshClient client = SshClient.setUpDefaultClient()) { ...further configuration of the client... client.start(); try (ClientSession session = client.connect(login, host, port) .verify(...timeout...) .getSession()) { session.addPasswordIdentity(password); session.auth().verify(...timeout...); try (ClientChannel channel = session.createChannel(ClientChannel.CHANNEL_SHELL)) { channel.setIn(new NoCloseInputStream(System.in)); channel.setOut(new NoCloseOutputStream(System.out)); channel.setErr(new NoCloseOutputStream(System.err)); channel.open(); channel.waitFor(ClientChannel.CLOSED, 0); } finally { session.close(false); } } finally { client.stop(); } }
SshClient
instance for the entire application and re-use it repeatedly in order to create as many sessions as necessary - possibly with different hosts, ports, users, passwords, etc. - including concurrently. In other words, except for exceptional cases, it is recommended to initialize one instance ofSshClient
for the application and then use throughout - including for multi-threading. As long as theSshClient
is not re-configured it should be multi-thread safe regardless of the target session being created.- Author:
- Apache MINA SSHD Project
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class org.apache.sshd.common.util.closeable.AbstractCloseable
AbstractCloseable.State
-
Nested classes/interfaces inherited from interface org.apache.sshd.common.AttributeRepository
AttributeRepository.AttributeKey<T>
-
Nested classes/interfaces inherited from interface org.apache.sshd.common.session.SessionHeartbeatController
SessionHeartbeatController.HeartbeatType
-
-
Field Summary
Fields Modifier and Type Field Description protected IoConnector
connector
static List<ServiceFactory>
DEFAULT_SERVICE_FACTORIES
static Factory<SshClient>
DEFAULT_SSH_CLIENT_FACTORY
static List<UserAuthFactory>
DEFAULT_USER_AUTH_FACTORIES
Default user authentication preferences if not setprotected SessionFactory
sessionFactory
protected List<UserAuthFactory>
userAuthFactories
protected UserInteraction
userInteraction
-
Fields inherited from class org.apache.sshd.common.helpers.AbstractFactoryManager
agentFactory, channelFactories, channelListenerProxy, channelListeners, executor, fileSystemFactory, forwarderFactory, forwardingFilter, globalRequestHandlers, ioServiceFactory, ioServiceFactoryFactory, randomFactory, serviceFactories, sessionListenerProxy, sessionListeners, sessionTimeoutListener, shutdownExecutor, timeoutListenerFuture, tunnelListenerProxy, tunnelListeners
-
Fields inherited from class org.apache.sshd.common.util.closeable.AbstractCloseable
closeFuture, futureLock, state
-
Fields inherited from class org.apache.sshd.common.util.logging.AbstractLoggingBean
log
-
Fields inherited from interface org.apache.sshd.common.channel.throttle.ChannelStreamPacketWriterResolver
NONE
-
Fields inherited from interface org.apache.sshd.client.ClientAuthenticationManager
DEFAULT_PASSWORD_PROMPTS, PASSWORD_PROMPTS, PREFERRED_AUTHS
-
Fields inherited from interface org.apache.sshd.client.ClientFactoryManager
CLIENT_IDENTIFICATION, DEFAULT_HEARTBEAT_INTERVAL, DEFAULT_HEARTBEAT_REPLY_WAIT, DEFAULT_IGNORE_INVALID_IDENTITIES, DEFAULT_KEEP_ALIVE_HEARTBEAT_STRING, DEFAULT_SEND_IMMEDIATE_IDENTIFICATION, DEFAULT_SEND_KEXINIT, HEARTBEAT_INTERVAL, HEARTBEAT_REPLY_WAIT, HEARTBEAT_REQUEST, IGNORE_INVALID_IDENTITIES, SEND_IMMEDIATE_IDENTIFICATION, SEND_IMMEDIATE_KEXINIT
-
Fields inherited from interface org.apache.sshd.common.Closeable
CLOSE_WAIT_TIMEOUT, DEFAULT_CLOSE_WAIT_TIMEOUT
-
Fields inherited from interface org.apache.sshd.common.FactoryManager
AGENT_FORWARDING_TYPE, AGENT_FORWARDING_TYPE_IETF, AGENT_FORWARDING_TYPE_OPENSSH, AUTH_TIMEOUT, CHANNEL_CLOSE_TIMEOUT, DEFAULT_AUTH_TIMEOUT, DEFAULT_CHANNEL_CLOSE_TIMEOUT, DEFAULT_DISCONNECT_TIMEOUT, DEFAULT_IDLE_TIMEOUT, DEFAULT_IGNORE_MESSAGE_FREQUENCY, DEFAULT_IGNORE_MESSAGE_SIZE, DEFAULT_IGNORE_MESSAGE_VARIANCE, DEFAULT_LIMIT_PACKET_SIZE, DEFAULT_MAX_IDENTIFICATION_SIZE, DEFAULT_MAX_PACKET_SIZE, DEFAULT_NIO_WORKERS, DEFAULT_NIO2_MIN_WRITE_TIMEOUT, DEFAULT_NIO2_READ_TIMEOUT, DEFAULT_REKEY_BYTES_LIMIT, DEFAULT_REKEY_PACKETS_LIMIT, DEFAULT_REKEY_TIME_LIMIT, DEFAULT_STOP_WAIT_TIME, DEFAULT_VERSION, DEFAULT_WINDOW_SIZE, DEFAULT_WINDOW_TIMEOUT, DISCONNECT_TIMEOUT, IDLE_TIMEOUT, IGNORE_MESSAGE_FREQUENCY, IGNORE_MESSAGE_SIZE, IGNORE_MESSAGE_VARIANCE, LIMIT_PACKET_SIZE, MAX_IDENTIFICATION_SIZE, MAX_PACKET_SIZE, NIO_WORKERS, NIO2_MIN_WRITE_TIMEOUT, NIO2_READ_BUFFER_SIZE, NIO2_READ_TIMEOUT, REKEY_BLOCKS_LIMIT, REKEY_BYTES_LIMIT, REKEY_PACKETS_LIMIT, REKEY_TIME_LIMIT, SOCKET_BACKLOG, SOCKET_KEEPALIVE, SOCKET_LINGER, SOCKET_RCVBUF, SOCKET_REUSEADDR, SOCKET_SNDBUF, STOP_WAIT_TIME, TCP_NODELAY, WINDOW_SIZE, WINDOW_TIMEOUT
-
Fields inherited from interface org.apache.sshd.common.PropertyResolver
EMPTY
-
Fields inherited from interface org.apache.sshd.common.session.SessionHeartbeatController
DEFAULT_CONNECTION_HEARTBEAT_INTERVAL, SESSION_HEARTBEAT_INTERVAL, SESSION_HEARTBEAT_TYPE
-
-
Constructor Summary
Constructors Constructor Description SshClient()
-
Method Summary
-
Methods inherited from class org.apache.sshd.common.helpers.AbstractFactoryManager
addChannelListener, addPortForwardingEventListener, addSessionListener, attributeKeys, clearAttributes, computeAttributeIfAbsent, createSessionTimeoutListener, getAgentFactory, getAttribute, getAttributesCount, getChannelFactories, getChannelListenerProxy, getChannelStreamPacketWriterResolver, getFileSystemFactory, getForwarderFactory, getForwardingFilter, getGlobalRequestHandlers, getIoServiceEventListener, getIoServiceFactory, getIoServiceFactoryFactory, getNioWorkers, getParentPropertyResolver, getPortForwardingEventListenerProxy, getProperties, getRandomFactory, getReservedSessionMessagesHandler, getScheduledExecutorService, getServiceFactories, getSessionDisconnectHandler, getSessionListenerProxy, getUnknownChannelReferenceHandler, getVersion, removeAttribute, removeChannelListener, removePortForwardingEventListener, removeSessionListener, removeSessionTimeout, resolveUnknownChannelReferenceHandler, setAgentFactory, setAttribute, setChannelFactories, setChannelStreamPacketWriterResolver, setFileSystemFactory, setForwarderFactory, setForwardingFilter, setGlobalRequestHandlers, setIoServiceEventListener, setIoServiceFactoryFactory, setNioWorkers, setParentPropertyResolver, setRandomFactory, setReservedSessionMessagesHandler, setScheduledExecutorService, setScheduledExecutorService, setServiceFactories, setSessionDisconnectHandler, setUnknownChannelReferenceHandler, setupSessionTimeout, stopSessionTimeoutListener
-
Methods inherited from class org.apache.sshd.common.kex.AbstractKexFactoryManager
getCipherFactories, getCompressionFactories, getDelegate, getKexExtensionHandler, getKeyExchangeFactories, getMacFactories, getSignatureFactories, resolveEffectiveFactories, resolveEffectiveProvider, setCipherFactories, setCompressionFactories, setKexExtensionHandler, setKeyExchangeFactories, setMacFactories, setSignatureFactories
-
Methods inherited from class org.apache.sshd.common.util.closeable.AbstractInnerCloseable
doCloseGracefully, doCloseImmediately
-
Methods inherited from class org.apache.sshd.common.util.closeable.AbstractCloseable
addCloseFutureListener, builder, close, getFutureLock, isClosed, isClosing, preClose, removeCloseFutureListener
-
Methods inherited from class org.apache.sshd.common.util.logging.AbstractLoggingBean
getSimplifiedLogger
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.apache.sshd.common.AttributeRepository
attributeKeys, getAttribute, getAttributesCount
-
Methods inherited from interface org.apache.sshd.common.AttributeStore
clearAttributes, computeAttributeIfAbsent, removeAttribute, setAttribute
-
Methods inherited from interface org.apache.sshd.common.channel.ChannelListenerManager
addChannelListener, getChannelListenerProxy, removeChannelListener
-
Methods inherited from interface org.apache.sshd.common.channel.throttle.ChannelStreamPacketWriterResolverManager
getChannelStreamPacketWriterResolver, resolveChannelStreamPacketWriter, resolveChannelStreamPacketWriterResolver, setChannelStreamPacketWriterResolver
-
Methods inherited from interface org.apache.sshd.client.ClientAuthenticationManager
setUserAuthFactoriesNames
-
Methods inherited from interface org.apache.sshd.client.session.ClientSessionCreator
connect, connect, connect, connect, connect, connect, connect, connect, connect
-
Methods inherited from interface org.apache.sshd.common.Closeable
addCloseFutureListener, close, close, isClosed, isClosing, isOpen, removeCloseFutureListener
-
Methods inherited from interface org.apache.sshd.common.FactoryManager
getAgentFactory, getAgentForwardingFilter, getChannelFactories, getFileSystemFactory, getForwarderFactory, getForwardingFilter, getGlobalRequestHandlers, getIoServiceFactory, getRandomFactory, getScheduledExecutorService, getServiceFactories, getTcpForwardingFilter, getVersion, getX11ForwardingFilter, resolveAttribute
-
Methods inherited from interface org.apache.sshd.common.io.IoServiceEventListenerManager
getIoServiceEventListener, setIoServiceEventListener
-
Methods inherited from interface org.apache.sshd.common.kex.extension.KexExtensionHandlerManager
getKexExtensionHandler, setKexExtensionHandler
-
Methods inherited from interface org.apache.sshd.common.kex.KexFactoryManager
getCipherFactories, getCipherFactoriesNameList, getCipherFactoriesNames, getCompressionFactories, getCompressionFactoriesNameList, getCompressionFactoriesNames, getKeyExchangeFactories, getMacFactories, getMacFactoriesNameList, getMacFactoriesNames, setCipherFactories, setCipherFactoriesNameList, setCipherFactoriesNames, setCipherFactoriesNames, setCompressionFactories, setCompressionFactoriesNameList, setCompressionFactoriesNames, setCompressionFactoriesNames, setKeyExchangeFactories, setMacFactories, setMacFactoriesNameList, setMacFactoriesNames, setMacFactoriesNames
-
Methods inherited from interface org.apache.sshd.common.forward.PortForwardingEventListenerManager
addPortForwardingEventListener, getPortForwardingEventListenerProxy, removePortForwardingEventListener
-
Methods inherited from interface org.apache.sshd.common.PropertyResolver
getBoolean, getBooleanProperty, getCharset, getInteger, getIntProperty, getLong, getLongProperty, getObject, getParentPropertyResolver, getProperties, getString, getStringProperty
-
Methods inherited from interface org.apache.sshd.common.session.ReservedSessionMessagesManager
getReservedSessionMessagesHandler, setReservedSessionMessagesHandler
-
Methods inherited from interface org.apache.sshd.common.session.SessionDisconnectHandlerManager
getSessionDisconnectHandler, setSessionDisconnectHandler
-
Methods inherited from interface org.apache.sshd.common.session.SessionHeartbeatController
disableSessionHeartbeat, getSessionHeartbeatInterval, getSessionHeartbeatType, setSessionHeartbeat
-
Methods inherited from interface org.apache.sshd.common.session.SessionListenerManager
addSessionListener, getSessionListenerProxy, removeSessionListener
-
Methods inherited from interface org.apache.sshd.common.signature.SignatureFactoriesManager
getSignatureFactories, getSignatureFactoriesNameList, getSignatureFactoriesNames, setSignatureFactories, setSignatureFactoriesNameList, setSignatureFactoriesNames, setSignatureFactoriesNames
-
Methods inherited from interface org.apache.sshd.common.session.UnknownChannelReferenceHandlerManager
getUnknownChannelReferenceHandler, resolveUnknownChannelReferenceHandler, setUnknownChannelReferenceHandler
-
Methods inherited from interface org.apache.sshd.common.auth.UserAuthFactoriesManager
getUserAuthFactoriesNameList, getUserAuthFactoriesNames, setUserAuthFactoriesNameList, setUserAuthFactoriesNames
-
-
-
-
Field Detail
-
DEFAULT_USER_AUTH_FACTORIES
public static final List<UserAuthFactory> DEFAULT_USER_AUTH_FACTORIES
Default user authentication preferences if not set- See Also:
- ssh_config(5) - PreferredAuthentications
-
DEFAULT_SERVICE_FACTORIES
public static final List<ServiceFactory> DEFAULT_SERVICE_FACTORIES
-
connector
protected IoConnector connector
-
sessionFactory
protected SessionFactory sessionFactory
-
userInteraction
protected UserInteraction userInteraction
-
userAuthFactories
protected List<UserAuthFactory> userAuthFactories
-
-
Method Detail
-
getSessionFactory
public SessionFactory getSessionFactory()
-
setSessionFactory
public void setSessionFactory(SessionFactory sessionFactory)
-
getClientProxyConnector
public ClientProxyConnector getClientProxyConnector()
- Specified by:
getClientProxyConnector
in interfaceClientProxyConnectorHolder
-
setClientProxyConnector
public void setClientProxyConnector(ClientProxyConnector proxyConnector)
- Specified by:
setClientProxyConnector
in interfaceClientProxyConnectorHolder
-
getServerKeyVerifier
public ServerKeyVerifier getServerKeyVerifier()
Description copied from interface:ClientAuthenticationManager
Retrieve the server key verifier to be used to check the key when connecting to an SSH server.- Specified by:
getServerKeyVerifier
in interfaceClientAuthenticationManager
- Returns:
- the
ServerKeyVerifier
to use - nevernull
-
setServerKeyVerifier
public void setServerKeyVerifier(ServerKeyVerifier serverKeyVerifier)
- Specified by:
setServerKeyVerifier
in interfaceClientAuthenticationManager
-
getHostConfigEntryResolver
public HostConfigEntryResolver getHostConfigEntryResolver()
- Specified by:
getHostConfigEntryResolver
in interfaceClientFactoryManager
- Returns:
- The
HostConfigEntryResolver
to use in order to resolve the effective session parameters - nevernull
-
setHostConfigEntryResolver
public void setHostConfigEntryResolver(HostConfigEntryResolver resolver)
- Specified by:
setHostConfigEntryResolver
in interfaceClientFactoryManager
-
getFilePasswordProvider
public FilePasswordProvider getFilePasswordProvider()
- Specified by:
getFilePasswordProvider
in interfaceFilePasswordProviderHolder
- Returns:
- The
FilePasswordProvider
to use if need to load encrypted identities keys - nevernull
- See Also:
FilePasswordProvider.EMPTY
-
setFilePasswordProvider
public void setFilePasswordProvider(FilePasswordProvider provider)
- Specified by:
setFilePasswordProvider
in interfaceFilePasswordProviderManager
-
getClientIdentityLoader
public ClientIdentityLoader getClientIdentityLoader()
- Specified by:
getClientIdentityLoader
in interfaceClientIdentityLoaderHolder
- Returns:
- The
ClientIdentityLoader
to use in order to load client key pair identities - nevernull
-
setClientIdentityLoader
public void setClientIdentityLoader(ClientIdentityLoader loader)
- Specified by:
setClientIdentityLoader
in interfaceClientIdentityLoaderManager
-
getUserInteraction
public UserInteraction getUserInteraction()
- Specified by:
getUserInteraction
in interfaceClientAuthenticationManager
- Returns:
- A
UserInteraction
object to communicate with the user (may benull
to indicate that no such communication is allowed)
-
setUserInteraction
public void setUserInteraction(UserInteraction userInteraction)
- Specified by:
setUserInteraction
in interfaceClientAuthenticationManager
-
getUserAuthFactories
public List<UserAuthFactory> getUserAuthFactories()
Description copied from interface:UserAuthFactoriesManager
Retrieve the list of named factories forUserAuth
objects.- Specified by:
getUserAuthFactories
in interfaceUserAuthFactoriesManager<ClientSession,UserAuth,UserAuthFactory>
- Returns:
- a list of named
UserAuth
factories, nevernull
/empty
-
setUserAuthFactories
public void setUserAuthFactories(List<UserAuthFactory> userAuthFactories)
- Specified by:
setUserAuthFactories
in interfaceUserAuthFactoriesManager<ClientSession,UserAuth,UserAuthFactory>
-
getRegisteredIdentities
public AuthenticationIdentitiesProvider getRegisteredIdentities()
- Specified by:
getRegisteredIdentities
in interfaceClientAuthenticationManager
- Returns:
- The
AuthenticationIdentitiesProvider
to be used for attempting password or public key authentication
-
getPasswordIdentityProvider
public PasswordIdentityProvider getPasswordIdentityProvider()
Description copied from interface:ClientAuthenticationManager
RetrievePasswordIdentityProvider
used to provide password candidates- Specified by:
getPasswordIdentityProvider
in interfaceClientAuthenticationManager
- Returns:
- The
PasswordIdentityProvider
instance - ignored ifnull
(i.e., no passwords available). - See Also:
ClientAuthenticationManager.addPasswordIdentity(String)
-
setPasswordIdentityProvider
public void setPasswordIdentityProvider(PasswordIdentityProvider provider)
- Specified by:
setPasswordIdentityProvider
in interfaceClientAuthenticationManager
-
addPasswordIdentity
public void addPasswordIdentity(String password)
- Specified by:
addPasswordIdentity
in interfaceClientAuthenticationManager
- Parameters:
password
- Password to be added - may not benull
/empty. Note: this password is in addition to whatever passwords are available via thePasswordIdentityProvider
(if any)
-
removePasswordIdentity
public String removePasswordIdentity(String password)
- Specified by:
removePasswordIdentity
in interfaceClientAuthenticationManager
- Parameters:
password
- The password to remove - ignored ifnull
/empty- Returns:
- The removed password - same one that was added via
ClientAuthenticationManager.addPasswordIdentity(String)
- ornull
if no match found
-
addPublicKeyIdentity
public void addPublicKeyIdentity(KeyPair kp)
- Specified by:
addPublicKeyIdentity
in interfaceClientAuthenticationManager
- Parameters:
kp
- TheKeyPair
to add - may not benull
Note: this key is in addition to whatever keys are available via theKeyIdentityProvider
(if any)
-
removePublicKeyIdentity
public KeyPair removePublicKeyIdentity(KeyPair kp)
- Specified by:
removePublicKeyIdentity
in interfaceClientAuthenticationManager
- Parameters:
kp
- TheKeyPair
to remove - ignored ifnull
- Returns:
- The removed
KeyPair
- same one that was added viaClientAuthenticationManager.addPublicKeyIdentity(KeyPair)
- ornull
if no match found
-
getKeyIdentityProvider
public KeyIdentityProvider getKeyIdentityProvider()
- Specified by:
getKeyIdentityProvider
in interfaceKeyIdentityProviderHolder
- Returns:
- The
KeyIdentityProvider
used to provide key-pair(s) for public key authentication
-
setKeyIdentityProvider
public void setKeyIdentityProvider(KeyIdentityProvider keyIdentityProvider)
- Specified by:
setKeyIdentityProvider
in interfaceKeyIdentityProviderHolder
-
checkConfig
protected void checkConfig()
- Overrides:
checkConfig
in classAbstractFactoryManager
-
isStarted
public boolean isStarted()
-
start
public void start()
Starts the SSH client and can start creating sessions using it. Ignored if alreadystarted
.
-
stop
public void stop()
-
open
public void open() throws IOException
- Throws:
IOException
-
getInnerCloseable
protected Closeable getInnerCloseable()
- Specified by:
getInnerCloseable
in classAbstractInnerCloseable
-
connect
public ConnectFuture connect(String username, String host, int port, AttributeRepository context, SocketAddress localAddress) throws IOException
Description copied from interface:ClientSessionCreator
Resolves the effectiveHostConfigEntry
and connects to it- Specified by:
connect
in interfaceClientSessionCreator
- Parameters:
username
- The intended usernamehost
- The target host name/address - nevernull
/emptyport
- The target portcontext
- An optional "context" to be attached to the established session if successfully connectedlocalAddress
- The local address to use - ifnull
an automatic ephemeral port and bind address is used- Returns:
- A
ConnectFuture
- Throws:
IOException
- If failed to resolve the effective target or connect to it
-
connect
public ConnectFuture connect(String username, SocketAddress targetAddress, AttributeRepository context, SocketAddress localAddress) throws IOException
Description copied from interface:ClientSessionCreator
Resolves the effectiveHostConfigEntry
and connects to it- Specified by:
connect
in interfaceClientSessionCreator
- Parameters:
username
- The intended usernametargetAddress
- The intended targetSocketAddress
- nevernull
. If this is anInetSocketAddress
then the effectiveHostConfigEntry
is resolved and used.context
- An optional "context" to be attached to the established session if successfully connectedlocalAddress
- The local address to use - ifnull
an automatic ephemeral port and bind address is used- Returns:
- A
ConnectFuture
- Throws:
IOException
- If failed to resolve the effective target or connect to it
-
connect
public ConnectFuture connect(HostConfigEntry hostConfig, AttributeRepository context, SocketAddress localAddress) throws IOException
- Specified by:
connect
in interfaceClientSessionCreator
- Parameters:
hostConfig
- The effectiveHostConfigEntry
to connect to - nevernull
context
- An optional "context" to be attached to the established session if successfully connectedlocalAddress
- The local address to use - ifnull
an automatic ephemeral port and bind address is used- Returns:
- A
ConnectFuture
- Throws:
IOException
- If failed to create the connection future
-
preloadClientIdentities
protected KeyIdentityProvider preloadClientIdentities(Collection<? extends NamedResource> locations) throws IOException
- Throws:
IOException
-
doConnect
protected ConnectFuture doConnect(String username, SocketAddress targetAddress, AttributeRepository context, SocketAddress localAddress, KeyIdentityProvider identities, boolean useDefaultIdentities) throws IOException
- Throws:
IOException
-
createConnectCompletionListener
protected SshFutureListener<IoConnectFuture> createConnectCompletionListener(ConnectFuture connectFuture, String username, SocketAddress address, KeyIdentityProvider identities, boolean useDefaultIdentities)
-
onConnectOperationComplete
protected void onConnectOperationComplete(IoSession ioSession, ConnectFuture connectFuture, String username, SocketAddress address, KeyIdentityProvider identities, boolean useDefaultIdentities)
-
setupDefaultSessionIdentities
protected void setupDefaultSessionIdentities(ClientSession session, KeyIdentityProvider extraIdentities)
-
createConnector
protected IoConnector createConnector()
-
createSessionFactory
protected SessionFactory createSessionFactory()
-
setUpDefaultSimpleClient
public static SimpleClient setUpDefaultSimpleClient()
Setup a default client, starts it and then wraps it as aSimpleClient
- Returns:
- The
SimpleClient
wrapper. Note: when the wrapper is closed the client is also stopped - See Also:
setUpDefaultClient()
,wrapAsSimpleClient(SshClient)
-
wrapAsSimpleClient
public static SimpleClient wrapAsSimpleClient(SshClient client)
Wraps anSshClient
instance as aSimpleClient
- Parameters:
client
- The client instance - nevernull
. Note: client must be started before the simple client wrapper is used.- Returns:
- The
SimpleClient
wrapper. Note: when the wrapper is closed the client is also stopped
-
setUpDefaultClient
public static SshClient setUpDefaultClient()
Setup a default client. The client does not require any additional setup.- Returns:
- a newly create
SshClient
with default configurations
-
setKeyPairProvider
public static <C extends SshClient> C setKeyPairProvider(C client, boolean strict, boolean supportedOnly, FilePasswordProvider provider, LinkOption... options) throws IOException, GeneralSecurityException
- Type Parameters:
C
- The generic client class- Parameters:
client
- TheSshClient
to updatedstrict
- Iftrue
then files that do not have the required access rights are excluded from considerationsupportedOnly
- Iftrue
then ignore identities that are not supported internallyprovider
- AFilePasswordProvider
- may benull
if the loaded keys are guaranteed not to be encrypted. The argument toFilePasswordProvider#getPassword
is the path of the file whose key is to be loadedoptions
- TheLinkOption
s to apply when checking for existence- Returns:
- The updated client instance - provided a non-
null
KeyPairProvider
was generated - Throws:
IOException
- If failed to access the file systemGeneralSecurityException
- If failed to load the keys- See Also:
setKeyPairProvider(SshClient, Path, boolean, boolean, FilePasswordProvider, LinkOption...)
-
setKeyPairProvider
public static <C extends SshClient> C setKeyPairProvider(C client, Path dir, boolean strict, boolean supportedOnly, FilePasswordProvider provider, LinkOption... options) throws IOException, GeneralSecurityException
- Type Parameters:
C
- The generic client class- Parameters:
client
- TheSshClient
to updateddir
- The folder to scan for the built-in identitiesstrict
- Iftrue
then files that do not have the required access rights are excluded from considerationsupportedOnly
- Iftrue
then ignore identities that are not supported internallyprovider
- AFilePasswordProvider
- may benull
if the loaded keys are guaranteed not to be encrypted. The argument toFilePasswordProvider#getPassword
is the path of the file whose key is to be loadedoptions
- TheLinkOption
s to apply when checking for existence- Returns:
- The updated client instance - provided a non-
null
KeyIdentityProvider
was generated - Throws:
IOException
- If failed to access the file systemGeneralSecurityException
- If failed to load the keys- See Also:
ClientIdentity.loadDefaultKeyPairProvider(Path, boolean, boolean, FilePasswordProvider, LinkOption...)
-
-