Class SshClient
java.lang.Object
org.apache.sshd.common.util.logging.AbstractLoggingBean
org.apache.sshd.common.util.closeable.IoBaseCloseable
org.apache.sshd.common.util.closeable.AbstractCloseable
org.apache.sshd.common.util.closeable.AbstractInnerCloseable
org.apache.sshd.common.kex.AbstractKexFactoryManager
org.apache.sshd.common.helpers.AbstractFactoryManager
org.apache.sshd.client.SshClient
- All Implemented Interfaces:
Closeable, AutoCloseable, Channel, ClientAuthenticationManager, ClientFactoryManager, org.apache.sshd.client.config.keys.ClientIdentityLoaderHolder, org.apache.sshd.client.config.keys.ClientIdentityLoaderManager, ClientSessionCreator, org.apache.sshd.common.AttributeRepository, org.apache.sshd.common.AttributeStore, org.apache.sshd.common.auth.UserAuthFactoriesManager<ClientSession, UserAuth, UserAuthFactory>, ChannelListenerManager, ChannelStreamWriterResolver, ChannelStreamWriterResolverManager, org.apache.sshd.common.Closeable, org.apache.sshd.common.config.keys.FilePasswordProviderHolder, org.apache.sshd.common.config.keys.FilePasswordProviderManager, FactoryManager, PortForwardingEventListenerManager, org.apache.sshd.common.io.IoServiceEventListenerManager, KexExtensionHandlerManager, KexFactoryManager, org.apache.sshd.common.keyprovider.KeyIdentityProviderHolder, org.apache.sshd.common.PropertyResolver, ReservedSessionMessagesManager, SessionDisconnectHandlerManager, org.apache.sshd.common.session.SessionHeartbeatController, SessionListenerManager, UnknownChannelReferenceHandlerManager, org.apache.sshd.common.signature.SignatureFactoriesHolder, org.apache.sshd.common.signature.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.- Author:
- Apache MINA SSHD Project
-
Nested Class Summary
Nested ClassesNested classes/interfaces inherited from class org.apache.sshd.common.util.closeable.AbstractCloseable
org.apache.sshd.common.util.closeable.AbstractCloseable.StateNested classes/interfaces inherited from interface org.apache.sshd.common.AttributeRepository
org.apache.sshd.common.AttributeRepository.AttributeKey<T>Nested classes/interfaces inherited from interface org.apache.sshd.common.session.SessionHeartbeatController
org.apache.sshd.common.session.SessionHeartbeatController.HeartbeatType -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected org.apache.sshd.common.io.IoConnectorstatic final List<ServiceFactory> static final org.apache.sshd.common.Factory<SshClient> static final List<UserAuthFactory> Default user authentication preferences if not setprotected SessionFactoryprotected List<UserAuthFactory> Fields inherited from class 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 ChannelStreamWriterResolver
NONEFields inherited from interface ClientSessionCreator
TARGET_SERVERFields inherited from interface FactoryManager
DEFAULT_VERSIONFields inherited from interface org.apache.sshd.common.PropertyResolver
EMPTY -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddPasswordIdentity(String password) voidprotected voidprotected voidconfigure(ClientSession session) Resolves the effectiveHostConfigEntryand connects to itconnect(String username, String host, int port, org.apache.sshd.common.AttributeRepository context, SocketAddress localAddress) Resolves the effectiveHostConfigEntryand connects to itconnect(String username, SocketAddress targetAddress, org.apache.sshd.common.AttributeRepository context, SocketAddress localAddress) Resolves the effectiveHostConfigEntryand connects to itconnect(org.apache.sshd.client.config.hosts.HostConfigEntry hostConfig, org.apache.sshd.common.AttributeRepository context, SocketAddress localAddress) protected org.apache.sshd.common.future.SshFutureListener<org.apache.sshd.common.io.IoConnectFuture> createConnectCompletionListener(ConnectFuture connectFuture, String username, SocketAddress address) protected org.apache.sshd.common.io.IoConnectorprotected SessionFactoryprotected ConnectFuturedoConnect(String username, InetSocketAddress targetAddress, ProxyData proxy, org.apache.sshd.common.AttributeRepository context, SocketAddress localAddress, org.apache.sshd.client.config.hosts.HostConfigEntry hostConfig) protected ConnectFuturedoConnect(org.apache.sshd.client.config.hosts.HostConfigEntry hostConfig, List<org.apache.sshd.client.config.hosts.HostConfigEntry> jumps, org.apache.sshd.common.AttributeRepository context, SocketAddress localAddress) protected org.apache.sshd.common.keyprovider.KeyIdentityProviderensureFilePasswordProvider(org.apache.sshd.common.keyprovider.KeyIdentityProvider identities) Sets this client'sFilePasswordProvideron theKeyIdentityProviderif it is anAbstractResourceKeyPairProvideror implementsFilePasswordProviderManagerand doesn't have one yet.org.apache.sshd.client.config.keys.ClientIdentityLoaderorg.apache.sshd.common.config.keys.FilePasswordProviderorg.apache.sshd.client.config.hosts.HostConfigEntryResolverprotected org.apache.sshd.common.Closeableprotected org.apache.sshd.common.keyprovider.KeyIdentityProvidergetKeyIdentities(org.apache.sshd.client.config.hosts.HostConfigEntry hostConfig) org.apache.sshd.common.keyprovider.KeyIdentityProviderorg.apache.sshd.client.auth.password.PasswordIdentityProviderRetrievePasswordIdentityProviderused to provide password candidatesorg.apache.sshd.client.auth.AuthenticationIdentitiesProviderRetrieve the server key verifier to be used to check the key when connecting to an SSH server.booleanprotected voidonConnectOperationComplete(org.apache.sshd.common.io.IoSession ioSession, ConnectFuture connectFuture, String username, SocketAddress address) voidopen()protected List<org.apache.sshd.client.config.hosts.HostConfigEntry> parseProxyJumps(String proxyJump, org.apache.sshd.common.AttributeRepository context) protected List<org.apache.sshd.client.config.hosts.HostConfigEntry> parseProxyJumps(org.apache.sshd.client.config.hosts.HostConfigEntry entry, org.apache.sshd.common.AttributeRepository context) protected org.apache.sshd.common.keyprovider.KeyIdentityProviderpreloadClientIdentities(Collection<? extends org.apache.sshd.common.NamedResource> locations) removePasswordIdentity(String password) protected org.apache.sshd.client.config.hosts.HostConfigEntryresolveHost(String username, String host, int port, org.apache.sshd.common.AttributeRepository context, SocketAddress localAddress) voidsetClientIdentityLoader(org.apache.sshd.client.config.keys.ClientIdentityLoader loader) voidsetFilePasswordProvider(org.apache.sshd.common.config.keys.FilePasswordProvider provider) voidvoidsetHostConfigEntryResolver(org.apache.sshd.client.config.hosts.HostConfigEntryResolver resolver) voidsetKeyIdentityProvider(org.apache.sshd.common.keyprovider.KeyIdentityProvider keyIdentityProvider) static <C extends SshClient>
CsetKeyPairProvider(C client, boolean strict, boolean supportedOnly, org.apache.sshd.common.config.keys.FilePasswordProvider provider, LinkOption... options) static <C extends SshClient>
CsetKeyPairProvider(C client, Path dir, boolean strict, boolean supportedOnly, org.apache.sshd.common.config.keys.FilePasswordProvider provider, LinkOption... options) voidsetNewHostKeysHandler(NewHostKeysHandler handler) voidvoidsetPasswordIdentityProvider(org.apache.sshd.client.auth.password.PasswordIdentityProvider provider) voidsetProxyDataFactory(ProxyDataFactory proxyDataFactory) voidvoidsetServerKeyVerifier(ServerKeyVerifier serverKeyVerifier) voidsetSessionFactory(SessionFactory sessionFactory) protected voidsetSessionKeyIdentities(ClientSession session) static SshClientSetup a default client.protected voidsetupDefaultSessionIdentities(ClientSession session, org.apache.sshd.common.keyprovider.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 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 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 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 ChannelListenerManager
addChannelListener, getChannelListenerProxy, removeChannelListenerMethods inherited from interface ChannelStreamWriterResolverManager
getChannelStreamWriterResolver, resolveChannelStreamWriter, resolveChannelStreamWriterResolver, setChannelStreamWriterResolverMethods inherited from interface ClientAuthenticationManager
setUserAuthFactoriesNamesMethods inherited from interface ClientSessionCreator
connect, connect, connect, connect, connect, connect, connect, connect, connectMethods inherited from interface org.apache.sshd.common.Closeable
close, isOpenMethods inherited from interface 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 KexExtensionHandlerManager
getKexExtensionHandler, setKexExtensionHandlerMethods inherited from interface 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 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 ReservedSessionMessagesManager
getReservedSessionMessagesHandler, setReservedSessionMessagesHandlerMethods inherited from interface SessionDisconnectHandlerManager
getSessionDisconnectHandler, setSessionDisconnectHandlerMethods inherited from interface org.apache.sshd.common.session.SessionHeartbeatController
disableSessionHeartbeat, getSessionHeartbeatInterval, getSessionHeartbeatType, setSessionHeartbeat, setSessionHeartbeatMethods inherited from interface 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 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
protected org.apache.sshd.common.io.IoConnector connector -
sessionFactory
-
userAuthFactories
-
-
Constructor Details
-
SshClient
public SshClient()
-
-
Method Details
-
getSessionFactory
-
setSessionFactory
-
getProxyDataFactory
-
setProxyDataFactory
-
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
public org.apache.sshd.client.config.hosts.HostConfigEntryResolver getHostConfigEntryResolver()- Specified by:
getHostConfigEntryResolverin interfaceClientFactoryManager- Returns:
- The
HostConfigEntryResolverto use in order to resolve the effective session parameters - nevernull
-
setHostConfigEntryResolver
public void setHostConfigEntryResolver(org.apache.sshd.client.config.hosts.HostConfigEntryResolver resolver) - Specified by:
setHostConfigEntryResolverin interfaceClientFactoryManager
-
getNewHostKeysHandler
- Specified by:
getNewHostKeysHandlerin interfaceClientFactoryManager
-
setNewHostKeysHandler
- Specified by:
setNewHostKeysHandlerin interfaceClientFactoryManager
-
getFilePasswordProvider
public org.apache.sshd.common.config.keys.FilePasswordProvider getFilePasswordProvider()- Specified by:
getFilePasswordProviderin interfaceorg.apache.sshd.common.config.keys.FilePasswordProviderHolder
-
setFilePasswordProvider
public void setFilePasswordProvider(org.apache.sshd.common.config.keys.FilePasswordProvider provider) - Specified by:
setFilePasswordProviderin interfaceorg.apache.sshd.common.config.keys.FilePasswordProviderManager
-
getClientIdentityLoader
public org.apache.sshd.client.config.keys.ClientIdentityLoader getClientIdentityLoader()- Specified by:
getClientIdentityLoaderin interfaceorg.apache.sshd.client.config.keys.ClientIdentityLoaderHolder
-
setClientIdentityLoader
public void setClientIdentityLoader(org.apache.sshd.client.config.keys.ClientIdentityLoader loader) - Specified by:
setClientIdentityLoaderin interfaceorg.apache.sshd.client.config.keys.ClientIdentityLoaderManager
-
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
- Specified by:
getUserAuthFactoriesin interfaceorg.apache.sshd.common.auth.UserAuthFactoriesManager<ClientSession, UserAuth, UserAuthFactory>
-
setUserAuthFactories
- Specified by:
setUserAuthFactoriesin interfaceorg.apache.sshd.common.auth.UserAuthFactoriesManager<ClientSession, UserAuth, UserAuthFactory>
-
getRegisteredIdentities
public org.apache.sshd.client.auth.AuthenticationIdentitiesProvider getRegisteredIdentities()- Specified by:
getRegisteredIdentitiesin interfaceClientAuthenticationManager- Returns:
- The
AuthenticationIdentitiesProviderto be used for attempting password or public key authentication
-
getPasswordIdentityProvider
public org.apache.sshd.client.auth.password.PasswordIdentityProvider 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
public void setPasswordIdentityProvider(org.apache.sshd.client.auth.password.PasswordIdentityProvider provider) - 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
public org.apache.sshd.common.keyprovider.KeyIdentityProvider getKeyIdentityProvider()- Specified by:
getKeyIdentityProviderin interfaceorg.apache.sshd.common.keyprovider.KeyIdentityProviderHolder
-
setKeyIdentityProvider
public void setKeyIdentityProvider(org.apache.sshd.common.keyprovider.KeyIdentityProvider keyIdentityProvider) - Specified by:
setKeyIdentityProviderin interfaceorg.apache.sshd.common.keyprovider.KeyIdentityProviderHolder
-
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
protected org.apache.sshd.common.Closeable getInnerCloseable()- Specified by:
getInnerCloseablein classorg.apache.sshd.common.util.closeable.AbstractInnerCloseable
-
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, org.apache.sshd.common.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, org.apache.sshd.common.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(org.apache.sshd.client.config.hosts.HostConfigEntry hostConfig, org.apache.sshd.common.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(org.apache.sshd.client.config.hosts.HostConfigEntry hostConfig, List<org.apache.sshd.client.config.hosts.HostConfigEntry> jumps, org.apache.sshd.common.AttributeRepository context, SocketAddress localAddress) throws IOException - Throws:
IOException
-
doConnect
protected ConnectFuture doConnect(String username, InetSocketAddress targetAddress, ProxyData proxy, org.apache.sshd.common.AttributeRepository context, SocketAddress localAddress, org.apache.sshd.client.config.hosts.HostConfigEntry hostConfig) throws IOException - Throws:
IOException
-
parseProxyJumps
protected List<org.apache.sshd.client.config.hosts.HostConfigEntry> parseProxyJumps(org.apache.sshd.client.config.hosts.HostConfigEntry entry, org.apache.sshd.common.AttributeRepository context) throws IOException - Throws:
IOException
-
parseProxyJumps
protected List<org.apache.sshd.client.config.hosts.HostConfigEntry> parseProxyJumps(String proxyJump, org.apache.sshd.common.AttributeRepository context) throws IOException - Throws:
IOException
-
resolveHost
protected org.apache.sshd.client.config.hosts.HostConfigEntry resolveHost(String username, String host, int port, org.apache.sshd.common.AttributeRepository context, SocketAddress localAddress) throws IOException - Throws:
IOException
-
createConnectCompletionListener
protected org.apache.sshd.common.future.SshFutureListener<org.apache.sshd.common.io.IoConnectFuture> createConnectCompletionListener(ConnectFuture connectFuture, String username, SocketAddress address) -
onConnectOperationComplete
protected void onConnectOperationComplete(org.apache.sshd.common.io.IoSession ioSession, ConnectFuture connectFuture, String username, SocketAddress address) throws IOException, GeneralSecurityException - Throws:
IOExceptionGeneralSecurityException
-
configure
- Throws:
IOExceptionGeneralSecurityException
-
setSessionKeyIdentities
protected void setSessionKeyIdentities(ClientSession session) throws IOException, GeneralSecurityException - Throws:
IOExceptionGeneralSecurityException
-
getKeyIdentities
protected org.apache.sshd.common.keyprovider.KeyIdentityProvider getKeyIdentities(org.apache.sshd.client.config.hosts.HostConfigEntry hostConfig) -
preloadClientIdentities
protected org.apache.sshd.common.keyprovider.KeyIdentityProvider preloadClientIdentities(Collection<? extends org.apache.sshd.common.NamedResource> locations) -
ensureFilePasswordProvider
protected org.apache.sshd.common.keyprovider.KeyIdentityProvider ensureFilePasswordProvider(org.apache.sshd.common.keyprovider.KeyIdentityProvider identities) 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, org.apache.sshd.common.keyprovider.KeyIdentityProvider extraIdentities) throws IOException, GeneralSecurityException - Throws:
IOExceptionGeneralSecurityException
-
createConnector
protected org.apache.sshd.common.io.IoConnector 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
-
setKeyPairProvider
public static <C extends SshClient> C setKeyPairProvider(C client, boolean strict, boolean supportedOnly, org.apache.sshd.common.config.keys.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, org.apache.sshd.common.config.keys.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:
-