cf.await(); try (ClientSession session = cf.getSession()) { for (KeyPair pair : provider.getKeys()) {
ClientSession session = client.connect("localhost", port).await().getSession(); session.authPassword("root", "");
private static ClientSession connectWithRetries(SshClient client, String username, String host, int port, int maxAttempts) throws Exception { ClientSession session = null; int retries = 0; do { ConnectFuture future = client.connect(username, host, port); future.await(); try { session = future.getSession(); } catch (Exception ex) { if (retries++ < maxAttempts) { Thread.sleep(2 * 1000); System.out.println("retrying (attempt " + retries + ") ..."); } else { throw ex; } } } while (session == null); return session; }
private ClientSession connectWithRetries(PrintWriter stdout, SshClient client, String username, String host, int port, int maxAttempts) throws Exception { ClientSession session = null; int retries = 0; do { ConnectFuture future = client.connect(username, host, port); future.await(); try { session = future.getSession(); } catch (Exception ex) { if (retries++ < maxAttempts) { Thread.sleep(2 * 1000); stdout.println("retrying (attempt " + retries + ") ..."); } else { throw ex; } } } while (session == null); return session; }
private ClientSession connectWithRetries(PrintWriter stdout, SshClient client, String username, String host, int port, int maxAttempts) throws Exception { ClientSession session = null; int retries = 0; do { ConnectFuture future = client.connect(username, host, port); future.await(); try { session = future.getSession(); } catch (Exception ex) { if (retries++ < maxAttempts) { Thread.sleep(2 * 1000); stdout.println("retrying (attempt " + retries + ") ..."); } else { throw ex; } } } while (session == null); return session; }
private static ClientSession connectWithRetries(SshClient client, String username, String host, int port, int maxAttempts) throws Exception { ClientSession session = null; int retries = 0; do { ConnectFuture future = client.connect(username, host, port); future.await(); try { session = future.getSession(); } catch (Exception ex) { if (retries++ < maxAttempts) { Thread.sleep(2 * 1000); System.out.println("retrying (attempt " + retries + ") ..."); } else { throw ex; } } } while (session == null); return session; }
private ClientSession connect(SshClient client) throws IOException, InterruptedException { int retries = 0; ClientSession session = null; do { final ConnectFuture future = client.connect(user, host, port); future.await(); try { session = future.getSession(); } catch (RuntimeSshException ex) { if (retries++ < attempts) { Thread.sleep(TimeUnit.SECONDS.toMillis(delay)); getLog().info("retrying (attempt " + retries + ") ..."); } else { throw ex; } } } while (session == null); return session; }
private ClientSession connect(SshClient client) throws IOException, InterruptedException { int retries = 0; ClientSession session = null; do { final ConnectFuture future = client.connect(user, host, port); future.await(); try { session = future.getSession(); } catch (RuntimeSshException ex) { if (retries++ < attempts) { Thread.sleep(TimeUnit.SECONDS.toMillis(delay)); getLog().info("retrying (attempt " + retries + ") ..."); } else { throw ex; } } } while (session == null); return session; }
private ClientSession connect(SshClient client) throws IOException, InterruptedException { int retries = 0; ClientSession session = null; do { final ConnectFuture future = client.connect(user, host, port); future.await(); try { session = future.getSession(); } catch (RuntimeSshException ex) { if (retries++ < attempts) { Thread.sleep(TimeUnit.SECONDS.toMillis(delay)); getLog().info("retrying (attempt " + retries + ") ..."); } else { throw ex; } } } while (session == null); return session; }
private ClientSession connect(SshClient client) throws IOException, InterruptedException { int retries = 0; ClientSession session = null; do { final ConnectFuture future = client.connect(user, host, port); future.await(); try { session = future.getSession(); } catch (RuntimeSshException ex) { if (retries++ < attempts) { Thread.sleep(TimeUnit.SECONDS.toMillis(delay)); getLog().info("retrying (attempt " + retries + ") ..."); } else { throw ex; } } } while (session == null); return session; }
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); } }
private static ClientSession connectWithRetries(SshClient client, ClientConfig config) throws Exception { ClientSession session = null; int retries = 0; do { ConnectFuture future = client.connect(config.getUser(), config.getHost(), config.getPort()); future.await(); try { session = future.getSession(); } catch (RuntimeSshException ex) { if (retries++ < config.getRetryAttempts()) { Thread.sleep(config.getRetryDelay() * 1000); System.out.println("retrying (attempt " + retries + ") ..."); } else { throw ex; } } } while (session == null); return session; }
@Test public void testConnectTimeout() throws Exception { SSHClient client = spy(this.client); SshClient ssh = spy(SshClient.setUpDefaultClient()); ConnectFuture future = mock(ConnectFuture.class); doReturn(ssh).when(client).createSshClient(); doReturn(future).when(ssh).connect(any(), any(), anyInt()); when(future.await(anyLong())).thenReturn(false); assertThrows(TimeLimitExceededException.class, client::connect); }
private static ClientSession connectWithRetries(SshClient client, ClientConfig config) throws Exception { ClientSession session = null; int retries = 0; do { ConnectFuture future = client.connect(config.getUser(), config.getHost(), config.getPort()); future.await(); try { session = future.getSession(); } catch (RuntimeSshException ex) { if (retries++ < config.getRetryAttempts()) { Thread.sleep(config.getRetryDelay() * 1000); System.out.println("retrying (attempt " + retries + ") ..."); } else { throw ex; } } } while (session == null); return session; }
if (!cfuture.await(softTimeout)) { throw new TimeLimitExceededException( String.format(
@Test public void testPasswordTimeout() throws Exception { SSHClient client = spy(this.client); SshClient ssh = spy(SshClient.setUpDefaultClient()); ConnectFuture future = mock(ConnectFuture.class); ClientSession session = mock(ClientSession.class); doReturn(ssh).when(client).createSshClient(); doReturn(future).when(ssh).connect(any(), any(), anyInt()); when(future.await(anyLong())).thenReturn(true); when(future.getSession()).thenReturn(session); AuthFuture authFuture = mock(AuthFuture.class); when(authFuture.await(anyLong())).thenReturn(false); when(session.auth()).thenReturn(authFuture); assertThrows(TimeLimitExceededException.class, () -> { client.connect(); client.authenticate(); }); } }
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; }
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();