ClientSession session = client.connect("localhost", port).await().getSession(); session.authPassword("root", "");
private void startSsh(final ChannelHandlerContext ctx, final SocketAddress address) { LOG.debug("Starting SSH to {} on channel: {}", address, ctx.channel()); final ConnectFuture sshConnectionFuture = sshClient.connect(authenticationHandler.getUsername(), address); sshConnectionFuture.addListener(new SshFutureListener<ConnectFuture>() { @Override public void operationComplete(final ConnectFuture future) { if (future.isConnected()) { handleSshSessionCreated(future, ctx); } else { handleSshSetupFailure(ctx, future.getException()); } } }); }
private void startSsh(final ChannelHandlerContext ctx, final SocketAddress address) { LOG.debug("Starting SSH to {} on channel: {}", address, ctx.channel()); final ConnectFuture sshConnectionFuture = sshClient.connect(authenticationHandler.getUsername(), address); sshConnectionFuture.addListener(new SshFutureListener<ConnectFuture>() { @Override public void operationComplete(final ConnectFuture future) { if (future.isConnected()) { handleSshSessionCreated(future, ctx); } else { handleSshSetupFailure(ctx, future.getException()); } } }); }
protected void connect(SshClient client) throws IOException, InterruptedException { int attempts = 10; do { final ConnectFuture future = client.connect(configuration.getUsername(), configuration.getHost(), configuration.getPort()); future.await(); try { session = future.getSession(); } catch (RuntimeSshException ex) { if (--attempts > 0) { Thread.sleep(TimeUnit.SECONDS.toMillis(2)); log.info("Waiting for SSH connection..."); } else { throw ex; } } } while (session == null); } }
ClientSession session = null; do { ConnectFuture future = client.connect(host, port); future.await(); try {
client = SshClient.setUpDefaultClient(); client.start(); ConnectFuture future = client.connect(host, Integer.parseInt(port)); ClientSession session = future.await().getSession(); if (!session.authPassword(user, pass).await().isSuccess()) {
private static ClientSession connect(SshClient client, final String user, KeyPair keyPair, final String ip, final int port) throws IOException, InterruptedException { ClientSession session = client.connect(user, ip, port).await().getSession(); int authState = ClientSession.WAIT_AUTH; while ((authState & ClientSession.WAIT_AUTH) != 0) { session.addPublicKeyIdentity(keyPair); log.info("Authenticating to " + user + "@" + ip); AuthFuture authFuture = session.auth(); authFuture.addListener(new SshFutureListener<AuthFuture>() { @Override public void operationComplete(AuthFuture authFuture) { log.info("Authentication completed with " + (authFuture.isSuccess() ? "success" : "failure") + " for " + user + "@" + ip + ":" + port); } }); authState = session.waitFor(ClientSession.WAIT_AUTH | ClientSession.CLOSED | ClientSession.AUTHED, 0); } if ((authState & ClientSession.CLOSED) != 0) { throw new IOException("Authentication failed for " + user + "@" + ip); } return session; }
ConnectFuture future = client.connect(hostname, Integer.parseInt(port)); future.await(); sshSession = future.getSession();
ConnectFuture future = client.connect(hostname, Integer.parseInt(port)); future.await(); sshSession = future.getSession();
try { clientSession = sshClient.connect(EncryptionTool.getInstance().decrypt(username), host, port).await().getSession(); if (password != null) { clientSession.addPasswordIdentity(EncryptionTool.getInstance().decrypt(password));
session = client.connect(m_host, m_port).await().getSession();