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,ChannelStreamWriterResolver,ChannelStreamWriterResolverManager,Closeable,FilePasswordProviderHolder,FilePasswordProviderManager,FactoryManager,PortForwardingEventListenerManager,IoServiceEventListenerManager,KexExtensionHandlerManager,KexFactoryManager,KeyIdentityProviderHolder,PropertyResolver,ReservedSessionMessagesManager,SessionDisconnectHandlerManager,SessionHeartbeatController,SessionListenerManager,UnknownChannelReferenceHandlerManager,SignatureFactoriesHolder,SignatureFactoriesManager
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 the start() method.
Sessions can then be created using on of the ClientSessionCreator.connect(String, String, int) or
ClientSessionCreator.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:
try (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();
}
}
Note: the idea is to have one 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 of SshClient for the application and then use throughout - including for multi-threading. As
long as the SshClient is not re-configured it should be multi-thread safe regardless of the target session
being created.-
Nested Class Summary
Nested classes/interfaces inherited from class org.apache.sshd.common.util.closeable.AbstractCloseable
AbstractCloseable.StateNested 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
FieldsModifier and TypeFieldDescriptionprivate ClientIdentityLoaderprotected IoConnectorstatic final List<ServiceFactory> static final List<UserAuthFactory> Default user authentication preferences if not setprivate FilePasswordProviderprivate HostBasedAuthenticationReporterprivate HostConfigEntryResolverprivate final AuthenticationIdentitiesProviderprivate KeyIdentityProviderprivate PasswordAuthenticationReporterprivate PasswordIdentityProviderprivate ClientProxyConnectorprivate PublicKeyAuthenticationReporterprivate ServerKeyVerifierprotected SessionFactoryprivate final AtomicBooleanprotected List<UserAuthFactory> private UserInteractionFields 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, tunnelListenersFields inherited from class org.apache.sshd.common.util.closeable.AbstractCloseable
closeFuture, futureLock, stateFields inherited from class org.apache.sshd.common.util.logging.AbstractLoggingBean
logFields inherited from interface org.apache.sshd.common.channel.throttle.ChannelStreamWriterResolver
NONEFields inherited from interface org.apache.sshd.client.session.ClientSessionCreator
TARGET_SERVERFields inherited from interface org.apache.sshd.common.FactoryManager
DEFAULT_VERSIONFields inherited from interface org.apache.sshd.common.PropertyResolver
EMPTY -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddPasswordIdentity(String password) voidprotected voidResolves the effectiveHostConfigEntryand connects to itconnect(String username, String host, int port, AttributeRepository context, SocketAddress localAddress) Resolves the effectiveHostConfigEntryand connects to itconnect(String username, SocketAddress targetAddress, AttributeRepository context, SocketAddress localAddress) Resolves the effectiveHostConfigEntryand connects to itconnect(HostConfigEntry hostConfig, AttributeRepository context, SocketAddress localAddress) protected SshFutureListener<IoConnectFuture> createConnectCompletionListener(ConnectFuture connectFuture, String username, SocketAddress address, KeyIdentityProvider identities, HostConfigEntry hostConfig) protected IoConnectorprotected SessionFactoryprotected ConnectFuturedoConnect(String username, SocketAddress targetAddress, AttributeRepository context, SocketAddress localAddress, KeyIdentityProvider identities, HostConfigEntry hostConfig) protected ConnectFuturedoConnect(HostConfigEntry hostConfig, List<HostConfigEntry> jumps, AttributeRepository context, SocketAddress localAddress) protected KeyIdentityProviderensureFilePasswordProvider(KeyIdentityProvider identities) Sets this client'sFilePasswordProvideron theKeyIdentityProviderif it is anAbstractResourceKeyPairProvideror implementsFilePasswordProviderManagerand doesn't have one yet.protected CloseableRetrievePasswordIdentityProviderused to provide password candidatesRetrieve the server key verifier to be used to check the key when connecting to an SSH server.Retrieve the list of named factories forUserAuthobjects.booleanprotected voidonConnectOperationComplete(IoSession ioSession, ConnectFuture connectFuture, String username, SocketAddress address, KeyIdentityProvider identities, HostConfigEntry hostConfig) voidopen()protected List<HostConfigEntry> parseProxyJumps(String proxyJump, AttributeRepository context) protected KeyIdentityProviderpreloadClientIdentities(Collection<? extends NamedResource> locations) removePasswordIdentity(String password) protected HostConfigEntryresolveHost(String username, String host, int port, AttributeRepository context, SocketAddress localAddress) voidvoidsetClientProxyConnector(ClientProxyConnector proxyConnector) voidsetFilePasswordProvider(FilePasswordProvider provider) voidvoidvoidsetKeyIdentityProvider(KeyIdentityProvider keyIdentityProvider) static <C extends SshClient>
CsetKeyPairProvider(C client, boolean strict, boolean supportedOnly, FilePasswordProvider provider, LinkOption... options) static <C extends SshClient>
CsetKeyPairProvider(C client, Path dir, boolean strict, boolean supportedOnly, FilePasswordProvider provider, LinkOption... options) voidvoidvoidvoidsetServerKeyVerifier(ServerKeyVerifier serverKeyVerifier) voidsetSessionFactory(SessionFactory sessionFactory) static SshClientSetup a default client.protected voidsetupDefaultSessionIdentities(ClientSession session, KeyIdentityProvider extraIdentities) static SimpleClientSetup a default client, starts it and then wraps it as aSimpleClientvoidsetUserAuthFactories(List<UserAuthFactory> userAuthFactories) voidsetUserInteraction(UserInteraction userInteraction) voidstart()Starts the SSH client and can start creating sessions using it.voidstop()toString()static SimpleClientwrapAsSimpleClient(SshClient client) Wraps anSshClientinstance as aSimpleClientMethods inherited from class org.apache.sshd.common.helpers.AbstractFactoryManager
addChannelListener, addPortForwardingEventListener, addSessionListener, attributeKeys, clearAttributes, computeAttributeIfAbsent, createSessionTimeoutListener, getAgentFactory, getAttribute, getAttributesCount, getChannelFactories, getChannelListenerProxy, getChannelStreamWriterResolver, 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, setChannelStreamWriterResolver, setFileSystemFactory, setForwarderFactory, setForwardingFilter, setGlobalRequestHandlers, setIoServiceEventListener, setIoServiceFactoryFactory, setNioWorkers, setParentPropertyResolver, setRandomFactory, setReservedSessionMessagesHandler, setScheduledExecutorService, setScheduledExecutorService, setServiceFactories, setSessionDisconnectHandler, setUnknownChannelReferenceHandler, setupSessionTimeout, stopSessionTimeoutListenerMethods inherited from class org.apache.sshd.common.kex.AbstractKexFactoryManager
getCipherFactories, getCompressionFactories, getDelegate, getKexExtensionHandler, getKeyExchangeFactories, getMacFactories, getSignatureFactories, resolveEffectiveFactories, resolveEffectiveProvider, setCipherFactories, setCompressionFactories, setKexExtensionHandler, setKeyExchangeFactories, setMacFactories, setSignatureFactoriesMethods inherited from class org.apache.sshd.common.util.closeable.AbstractInnerCloseable
doCloseGracefully, doCloseImmediatelyMethods inherited from class org.apache.sshd.common.util.closeable.AbstractCloseable
addCloseFutureListener, builder, close, getFutureLock, isClosed, isClosing, preClose, removeCloseFutureListenerMethods inherited from class org.apache.sshd.common.util.logging.AbstractLoggingBean
debug, debug, debug, debug, debug, error, error, error, error, error, getSimplifiedLogger, info, info, warn, warn, warn, warn, warn, warn, warn, warnMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface org.apache.sshd.common.AttributeRepository
attributeKeys, getAttribute, getAttributesCountMethods inherited from interface org.apache.sshd.common.AttributeStore
clearAttributes, computeAttributeIfAbsent, removeAttribute, setAttributeMethods inherited from interface org.apache.sshd.common.channel.ChannelListenerManager
addChannelListener, getChannelListenerProxy, removeChannelListenerMethods inherited from interface org.apache.sshd.common.channel.throttle.ChannelStreamWriterResolverManager
getChannelStreamWriterResolver, resolveChannelStreamWriter, resolveChannelStreamWriterResolver, setChannelStreamWriterResolverMethods inherited from interface org.apache.sshd.client.ClientAuthenticationManager
setUserAuthFactoriesNamesMethods inherited from interface org.apache.sshd.client.session.ClientSessionCreator
connect, connect, connect, connect, connect, connect, connect, connect, connectMethods inherited from interface org.apache.sshd.common.Closeable
addCloseFutureListener, close, close, isClosed, isClosing, isOpen, removeCloseFutureListenerMethods inherited from interface org.apache.sshd.common.FactoryManager
getAgentFactory, getAgentForwardingFilter, getChannelFactories, getFileSystemFactory, getForwarderFactory, getForwardingFilter, getGlobalRequestHandlers, getIoServiceFactory, getRandomFactory, getScheduledExecutorService, getServiceFactories, getTcpForwardingFilter, getVersion, getX11ForwardingFilter, resolveAttributeMethods inherited from interface org.apache.sshd.common.io.IoServiceEventListenerManager
getIoServiceEventListener, setIoServiceEventListenerMethods inherited from interface org.apache.sshd.common.kex.extension.KexExtensionHandlerManager
getKexExtensionHandler, setKexExtensionHandlerMethods 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, setMacFactoriesNamesMethods inherited from interface org.apache.sshd.common.forward.PortForwardingEventListenerManager
addPortForwardingEventListener, getPortForwardingEventListenerProxy, removePortForwardingEventListenerMethods inherited from interface org.apache.sshd.common.PropertyResolver
getBoolean, getBooleanProperty, getCharset, getInteger, getIntProperty, getLong, getLongProperty, getObject, getParentPropertyResolver, getProperties, getString, getStringProperty, isEmptyMethods inherited from interface org.apache.sshd.common.session.ReservedSessionMessagesManager
getReservedSessionMessagesHandler, setReservedSessionMessagesHandlerMethods inherited from interface org.apache.sshd.common.session.SessionDisconnectHandlerManager
getSessionDisconnectHandler, setSessionDisconnectHandlerMethods inherited from interface org.apache.sshd.common.session.SessionHeartbeatController
disableSessionHeartbeat, getSessionHeartbeatInterval, getSessionHeartbeatType, setSessionHeartbeat, setSessionHeartbeatMethods inherited from interface org.apache.sshd.common.session.SessionListenerManager
addSessionListener, getSessionListenerProxy, removeSessionListenerMethods inherited from interface org.apache.sshd.common.signature.SignatureFactoriesHolder
getSignatureFactories, getSignatureFactoriesNameList, getSignatureFactoriesNamesMethods inherited from interface org.apache.sshd.common.signature.SignatureFactoriesManager
setSignatureFactories, setSignatureFactoriesNameList, setSignatureFactoriesNames, setSignatureFactoriesNamesMethods inherited from interface org.apache.sshd.common.session.UnknownChannelReferenceHandlerManager
getUnknownChannelReferenceHandler, resolveUnknownChannelReferenceHandler, setUnknownChannelReferenceHandlerMethods inherited from interface org.apache.sshd.common.auth.UserAuthFactoriesManager
getUserAuthFactoriesNameList, getUserAuthFactoriesNames, setUserAuthFactoriesNameList, setUserAuthFactoriesNames
-
Field Details
-
DEFAULT_SSH_CLIENT_FACTORY
-
DEFAULT_USER_AUTH_FACTORIES
Default user authentication preferences if not set- See Also:
-
DEFAULT_SERVICE_FACTORIES
-
connector
-
sessionFactory
-
userAuthFactories
-
proxyConnector
-
serverKeyVerifier
-
hostConfigEntryResolver
-
clientIdentityLoader
-
keyIdentityProvider
-
publicKeyAuthenticationReporter
-
filePasswordProvider
-
passwordIdentityProvider
-
passwordAuthenticationReporter
-
hostBasedAuthenticationReporter
-
userInteraction
-
identities
-
identitiesProvider
-
started
-
-
Constructor Details
-
SshClient
public SshClient()
-
-
Method Details
-
getSessionFactory
-
setSessionFactory
-
getClientProxyConnector
- Specified by:
getClientProxyConnectorin interfaceClientProxyConnectorHolder
-
setClientProxyConnector
- Specified by:
setClientProxyConnectorin interfaceClientProxyConnectorHolder
-
getServerKeyVerifier
Description copied from interface:ClientAuthenticationManagerRetrieve the server key verifier to be used to check the key when connecting to an SSH server.- Specified by:
getServerKeyVerifierin interfaceClientAuthenticationManager- Returns:
- the
ServerKeyVerifierto use - nevernull
-
setServerKeyVerifier
- Specified by:
setServerKeyVerifierin interfaceClientAuthenticationManager
-
getHostConfigEntryResolver
- Specified by:
getHostConfigEntryResolverin interfaceClientFactoryManager- Returns:
- The
HostConfigEntryResolverto use in order to resolve the effective session parameters - nevernull
-
setHostConfigEntryResolver
- Specified by:
setHostConfigEntryResolverin interfaceClientFactoryManager
-
getFilePasswordProvider
- Specified by:
getFilePasswordProviderin interfaceFilePasswordProviderHolder- Returns:
- The
FilePasswordProviderto use if need to load encrypted identities keys - nevernull - See Also:
-
setFilePasswordProvider
- Specified by:
setFilePasswordProviderin interfaceFilePasswordProviderManager
-
getClientIdentityLoader
- Specified by:
getClientIdentityLoaderin interfaceClientIdentityLoaderHolder- Returns:
- The
ClientIdentityLoaderto use in order to load client key pair identities - nevernull
-
setClientIdentityLoader
- Specified by:
setClientIdentityLoaderin interfaceClientIdentityLoaderManager
-
getUserInteraction
- Specified by:
getUserInteractionin interfaceClientAuthenticationManager- Returns:
- A
UserInteractionobject to communicate with the user (may benullto indicate that no such communication is allowed)
-
setUserInteraction
- Specified by:
setUserInteractionin interfaceClientAuthenticationManager
-
getPasswordAuthenticationReporter
- Specified by:
getPasswordAuthenticationReporterin interfaceClientAuthenticationManager
-
setPasswordAuthenticationReporter
- Specified by:
setPasswordAuthenticationReporterin interfaceClientAuthenticationManager
-
getHostBasedAuthenticationReporter
- Specified by:
getHostBasedAuthenticationReporterin interfaceClientAuthenticationManager
-
setHostBasedAuthenticationReporter
- Specified by:
setHostBasedAuthenticationReporterin interfaceClientAuthenticationManager
-
getUserAuthFactories
Description copied from interface:UserAuthFactoriesManagerRetrieve the list of named factories forUserAuthobjects.- Specified by:
getUserAuthFactoriesin interfaceUserAuthFactoriesManager<ClientSession,UserAuth, UserAuthFactory> - Returns:
- a list of named
UserAuthfactories, nevernull/empty
-
setUserAuthFactories
- Specified by:
setUserAuthFactoriesin interfaceUserAuthFactoriesManager<ClientSession,UserAuth, UserAuthFactory>
-
getRegisteredIdentities
- Specified by:
getRegisteredIdentitiesin interfaceClientAuthenticationManager- Returns:
- The
AuthenticationIdentitiesProviderto be used for attempting password or public key authentication
-
getPasswordIdentityProvider
Description copied from interface:ClientAuthenticationManagerRetrievePasswordIdentityProviderused to provide password candidates- Specified by:
getPasswordIdentityProviderin interfaceClientAuthenticationManager- Returns:
- The
PasswordIdentityProviderinstance - ignored ifnull(i.e., no passwords available). - See Also:
-
setPasswordIdentityProvider
- Specified by:
setPasswordIdentityProviderin interfaceClientAuthenticationManager
-
addPasswordIdentity
- Specified by:
addPasswordIdentityin 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
- Specified by:
removePasswordIdentityin interfaceClientAuthenticationManager- Parameters:
password- The password to remove - ignored ifnull/empty- Returns:
- The removed password - same one that was added via
ClientAuthenticationManager.addPasswordIdentity(String)- ornullif no match found
-
addPublicKeyIdentity
- Specified by:
addPublicKeyIdentityin interfaceClientAuthenticationManager- Parameters:
kp- TheKeyPairto add - may not benullNote: this key is in addition to whatever keys are available via theKeyIdentityProvider(if any)
-
removePublicKeyIdentity
- Specified by:
removePublicKeyIdentityin interfaceClientAuthenticationManager- Parameters:
kp- TheKeyPairto remove - ignored ifnull- Returns:
- The removed
KeyPair- same one that was added viaClientAuthenticationManager.addPublicKeyIdentity(KeyPair)- ornullif no match found
-
getKeyIdentityProvider
- Specified by:
getKeyIdentityProviderin interfaceKeyIdentityProviderHolder- Returns:
- The
KeyIdentityProviderused to provide key-pair(s) for public key authentication
-
setKeyIdentityProvider
- Specified by:
setKeyIdentityProviderin interfaceKeyIdentityProviderHolder
-
getPublicKeyAuthenticationReporter
- Specified by:
getPublicKeyAuthenticationReporterin interfaceClientAuthenticationManager
-
setPublicKeyAuthenticationReporter
- Specified by:
setPublicKeyAuthenticationReporterin interfaceClientAuthenticationManager
-
checkConfig
protected void checkConfig()- Overrides:
checkConfigin 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
- Throws:
IOException
-
getInnerCloseable
- Specified by:
getInnerCloseablein classAbstractInnerCloseable
-
connect
Description copied from interface:ClientSessionCreatorResolves the effectiveHostConfigEntryand connects to it- Specified by:
connectin interfaceClientSessionCreator- Parameters:
uriStr- The server uri to connect to- Returns:
- A
ConnectFuture - Throws:
IOException- If failed to resolve the effective target or connect to it- See Also:
-
connect
public ConnectFuture connect(String username, SocketAddress targetAddress, AttributeRepository context, SocketAddress localAddress) throws IOException Description copied from interface:ClientSessionCreatorResolves the effectiveHostConfigEntryand connects to it- Specified by:
connectin interfaceClientSessionCreator- Parameters:
username- The intended usernametargetAddress- The intended targetSocketAddress- nevernull. If this is anInetSocketAddressthen the effectiveHostConfigEntryis resolved and used.context- An optional "context" to be attached to the established session if successfully connectedlocalAddress- The local address to use - ifnullan 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, String host, int port, AttributeRepository context, SocketAddress localAddress) throws IOException Description copied from interface:ClientSessionCreatorResolves the effectiveHostConfigEntryand connects to it- Specified by:
connectin 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 - ifnullan 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:
connectin interfaceClientSessionCreator- Parameters:
hostConfig- The effectiveHostConfigEntryto connect to - nevernullcontext- An optional "context" to be attached to the established session if successfully connectedlocalAddress- The local address to use - ifnullan automatic ephemeral port and bind address is used- Returns:
- A
ConnectFuture - Throws:
IOException- If failed to create the connection future
-
doConnect
protected ConnectFuture doConnect(HostConfigEntry hostConfig, List<HostConfigEntry> jumps, AttributeRepository context, SocketAddress localAddress) throws IOException - Throws:
IOException
-
doConnect
protected ConnectFuture doConnect(String username, SocketAddress targetAddress, AttributeRepository context, SocketAddress localAddress, KeyIdentityProvider identities, HostConfigEntry hostConfig) throws IOException - Throws:
IOException
-
parseProxyJumps
protected List<HostConfigEntry> parseProxyJumps(String proxyJump, AttributeRepository context) throws IOException - Throws:
IOException
-
resolveHost
protected HostConfigEntry resolveHost(String username, String host, int port, AttributeRepository context, SocketAddress localAddress) throws IOException - Throws:
IOException
-
preloadClientIdentities
protected KeyIdentityProvider preloadClientIdentities(Collection<? extends NamedResource> locations) throws IOException - Throws:
IOException
-
createConnectCompletionListener
protected SshFutureListener<IoConnectFuture> createConnectCompletionListener(ConnectFuture connectFuture, String username, SocketAddress address, KeyIdentityProvider identities, HostConfigEntry hostConfig) -
onConnectOperationComplete
protected void onConnectOperationComplete(IoSession ioSession, ConnectFuture connectFuture, String username, SocketAddress address, KeyIdentityProvider identities, HostConfigEntry hostConfig) throws IOException, GeneralSecurityException - Throws:
IOExceptionGeneralSecurityException
-
ensureFilePasswordProvider
Sets this client'sFilePasswordProvideron theKeyIdentityProviderif it is anAbstractResourceKeyPairProvideror implementsFilePasswordProviderManagerand doesn't have one yet. If the givenidentitiesis aMultiKeyIdentityProvider, the wrapped identity providers are set up.- Parameters:
identities-KeyIdentityProviderto set up- Returns:
- a
KeyIdentityProviderconfigured with aFilePasswordProvider - See Also:
-
setupDefaultSessionIdentities
protected void setupDefaultSessionIdentities(ClientSession session, KeyIdentityProvider extraIdentities) throws IOException, GeneralSecurityException - Throws:
IOExceptionGeneralSecurityException
-
createConnector
-
createSessionFactory
-
toString
-
setUpDefaultSimpleClient
Setup a default client, starts it and then wraps it as aSimpleClient- Returns:
- The
SimpleClientwrapper. Note: when the wrapper is closed the client is also stopped - See Also:
-
wrapAsSimpleClient
Wraps anSshClientinstance as aSimpleClient- Parameters:
client- The client instance - nevernull. Note: client must be started before the simple client wrapper is used.- Returns:
- The
SimpleClientwrapper. Note: when the wrapper is closed the client is also stopped
-
setUpDefaultClient
Setup a default client. The client does not require any additional setup.- Returns:
- a newly create
SshClientwith 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- TheSshClientto updatedstrict- Iftruethen files that do not have the required access rights are excluded from considerationsupportedOnly- Iftruethen ignore identities that are not supported internallyprovider- AFilePasswordProvider- may benullif the loaded keys are guaranteed not to be encrypted. The argument toFilePasswordProvider#getPasswordis the path of the file whose key is to be loadedoptions- TheLinkOptions to apply when checking for existence- Returns:
- The updated client instance - provided a non-
nullKeyPairProviderwas generated - Throws:
IOException- If failed to access the file systemGeneralSecurityException- If failed to load the keys- See Also:
-
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- TheSshClientto updateddir- The folder to scan for the built-in identitiesstrict- Iftruethen files that do not have the required access rights are excluded from considerationsupportedOnly- Iftruethen ignore identities that are not supported internallyprovider- AFilePasswordProvider- may benullif the loaded keys are guaranteed not to be encrypted. The argument toFilePasswordProvider#getPasswordis the path of the file whose key is to be loadedoptions- TheLinkOptions to apply when checking for existence- Returns:
- The updated client instance - provided a non-
nullKeyIdentityProviderwas generated - Throws:
IOException- If failed to access the file systemGeneralSecurityException- If failed to load the keys- See Also:
-