public class SshClient extends AbstractFactoryManager implements ClientFactoryManager, Closeable
setUpDefaultClient()
. The next step is to
start the client using the start()
method.
Sessions can then be created using on of the
connect(String, int)
or connect(java.net.SocketAddress)
methods.
The client can be stopped at anytime using the stop()
method.
Following is an example of using the SshClient:
SshClient client = SshClient.setUpDefaultClient(); client.start(); try { ClientSession session = client.connect(login, host, port).await().getSession(); session.addPasswordIdentity(password); session.auth().verify(); ClientChannel channel = session.createChannel("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); session.close(false); } finally { client.stop(); }
CloseableUtils.AbstractCloseable.State
Modifier and Type | Field and Description |
---|---|
protected IoConnector |
connector |
static Factory<SshClient> |
DEFAULT_SSH_CLIENT_FACTORY |
protected SessionFactory |
sessionFactory |
protected List<NamedFactory<UserAuth>> |
userAuthFactories |
protected UserInteraction |
userInteraction |
agentFactory, channelFactories, cipherFactories, compressionFactories, executor, fileSystemFactory, globalRequestHandlers, ioServiceFactory, ioServiceFactoryFactory, keyExchangeFactories, keyPairProvider, macFactories, properties, randomFactory, serviceFactories, sessionTimeoutListener, shutdownExecutor, signatureFactories, tcpipForwarderFactory, tcpipForwardingFilter, timeoutListenerFuture, version
closeFuture, lock, log, state
HEARTBEAT_INTERVAL, HEARTBEAT_REQUEST, PASSWORD_PROMPTS, PREFERRED_AUTHS
AUTH_TIMEOUT, CHANNEL_CLOSE_TIMEOUT, DEFAULT_NIO_WORKERS, DISCONNECT_TIMEOUT, IDLE_TIMEOUT, MAX_PACKET_SIZE, NIO_WORKERS, SOCKET_BACKLOG, SOCKET_KEEPALIVE, SOCKET_LINGER, SOCKET_RCVBUF, SOCKET_REUSEADDR, SOCKET_SNDBUF, TCP_NODELAY, WINDOW_SIZE
Constructor and Description |
---|
SshClient() |
createSessionTimeoutListener, getAgentFactory, getChannelFactories, getCipherFactories, getCompressionFactories, getFileSystemFactory, getGlobalRequestHandlers, getIoServiceFactory, getIoServiceFactoryFactory, getKeyExchangeFactories, getKeyPairProvider, getMacFactories, getNioWorkers, getProperties, getRandomFactory, getScheduledExecutorService, getServiceFactories, getSignatureFactories, getTcpipForwarderFactory, getTcpipForwardingFilter, getVersion, loadVersion, removeSessionTimeout, setAgentFactory, setChannelFactories, setCipherFactories, setCompressionFactories, setFileSystemFactory, setGlobalRequestHandlers, setIoServiceFactoryFactory, setKeyExchangeFactories, setKeyPairProvider, setMacFactories, setNioWorkers, setProperties, setRandomFactory, setScheduledExecutorService, setScheduledExecutorService, setServiceFactories, setSignatureFactories, setTcpipForwarderFactory, setTcpipForwardingFilter, setupSessionTimeout, stopSessionTimeoutListener
doCloseGracefully, doCloseImmediately
builder, close, isClosed, isClosing, preClose
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
getTcpipForwarderFactory
getAgentFactory, getChannelFactories, getCipherFactories, getCompressionFactories, getFileSystemFactory, getGlobalRequestHandlers, getIoServiceFactory, getKeyExchangeFactories, getKeyPairProvider, getMacFactories, getProperties, getRandomFactory, getScheduledExecutorService, getServiceFactories, getSignatureFactories, getTcpipForwardingFilter, getVersion
protected IoConnector connector
protected SessionFactory sessionFactory
protected UserInteraction userInteraction
protected List<NamedFactory<UserAuth>> userAuthFactories
public SessionFactory getSessionFactory()
public void setSessionFactory(SessionFactory sessionFactory)
public ServerKeyVerifier getServerKeyVerifier()
ClientFactoryManager
getServerKeyVerifier
in interface ClientFactoryManager
public void setServerKeyVerifier(ServerKeyVerifier serverKeyVerifier)
public UserInteraction getUserInteraction()
ClientFactoryManager
getUserInteraction
in interface ClientFactoryManager
UserInteraction
or null
public void setUserInteraction(UserInteraction userInteraction)
public List<NamedFactory<UserAuth>> getUserAuthFactories()
ClientFactoryManager
getUserAuthFactories
in interface ClientFactoryManager
UserAuth
factories, never null
public void setUserAuthFactories(List<NamedFactory<UserAuth>> userAuthFactories)
protected void checkConfig()
public void start()
public void stop()
public void open() throws IOException
IOException
protected Closeable getInnerCloseable()
getInnerCloseable
in class CloseableUtils.AbstractInnerCloseable
@Deprecated public ConnectFuture connect(String host, int port) throws IOException
connect(String, String, int)
insteadIOException
public ConnectFuture connect(String username, String host, int port) throws IOException
IOException
@Deprecated public ConnectFuture connect(SocketAddress address)
public ConnectFuture connect(String username, SocketAddress address)
protected IoConnector createConnector()
protected SessionFactory createSessionFactory()
public static SshClient setUpDefaultClient()
Copyright © 2008–2016 The Apache Software Foundation. All rights reserved.