/** * Same as {@link #disconnect()}. * * @throws IOException */ @Override public void close() throws IOException { disconnect(); }
SSHClient ssh = new SSHClient(); //ssh.useCompression(); ssh.loadKnownHosts(); ssh.connect("localhost"); try { ssh.authPublickey(System.getProperty("user.name")); new SCPDownloadClient(ssh).copy("ten", "/tmp"); } finally { ssh.disconnect(); }
public void stopClient() { if (client != null && client.isConnected()) { try { client.disconnect(); } catch (IOException e) { throw new RuntimeException(e); } finally { client = null; } } else if (client != null) { client = null; } }
@Test public void listenerNotifiedOnClientDisconnect() throws IOException { fixture.getClient().disconnect(); assertTrue(disconnected.get()); }
@Test public void joinNotifiedOnClientDisconnect() throws IOException { fixture.getClient().disconnect(); assertTrue(joinToClientTransport(2)); }
@Test public void shouldVerifyAlgorithm() throws IOException { for (int i = 0; i < 10; i++) { logger.info("--> Attempt {}", i); configureServer(fixture.getServer()); fixture.start(); config.setRandomFactory(randomFactory); Config config = getClientConfig(this.config); SSHClient sshClient = fixture.connectClient(fixture.setupClient(config)); assertThat("should be connected", sshClient.isConnected()); sshClient.disconnect(); // fixture.stopServer(); fixture.stopClient(); } }
@Test public void shouldNotThrowTimeoutOnDisconnect() throws IOException { fixture.getClient().authPassword("u", "u"); Session session = fixture.getClient().startSession(); session.allocateDefaultPTY(); Session.Shell shell = session.startShell(); session.close(); fixture.getClient().disconnect(); } }
public void close() { if (closed) { return; } closed = true; try { ssh.disconnect(); if (privateKeyFile != null) { privateKeyFile.delete(); } if (script != null) { script.cleanup(); } } catch (IOException e) { StringBuilder sb = new StringBuilder(String.format("failed to close connection")); sb.append(String.format("[host:%s, port:%s, user:%s, timeout:%s]\n", hostname, port, username, timeout)); logger.warn(sb.toString(), e); } }
SSHClient ssh = new SSHClient(); ssh.loadKnownHosts(); ssh.connect("nameOfServer"); ssh.authPublickey("userId"); Session session = ssh.startSession(); Command cmd = session.exec("yourCommand"); System.out.println(cmd.getOutputAsString()); session.close(); ssh.disconnect();
/** * Same as {@link #disconnect()}. * * @throws IOException */ @Override public void close() throws IOException { disconnect(); }
/** * Same as {@link #disconnect()}. * * @throws IOException */ @Override public void close() throws IOException { disconnect(); }
@Override public void clear() { if (ssh != null && ssh.isConnected()) { try { if (LOG.isTraceEnabled()) LOG.trace("Disconnecting SshjClientConnection {} ({})", this, System.identityHashCode(this)); ssh.disconnect(); } catch (IOException e) { if (LOG.isDebugEnabled()) LOG.debug("<< exception disconnecting from {}: {}", e, e.getMessage()); } ssh = null; } }
@Override public void clear() { if (ssh != null && ssh.isConnected()) { try { if (LOG.isTraceEnabled()) LOG.trace("Disconnecting SshjClientConnection {} ({})", this, System.identityHashCode(this)); ssh.disconnect(); } catch (IOException e) { if (LOG.isDebugEnabled()) LOG.debug("<< exception disconnecting from {}: {}", e, e.getMessage()); } } ssh = null; }
@Override public void teardown() { try { client.disconnect(); } catch (IOException ignored) { // } actualItestHost.teardown(); }
public void dispose(InvocationContext invocationContext) throws GfacException { super.dispose(invocationContext); try { if (ssh != null && ssh.isConnected()) { ssh.disconnect(); } } catch (Exception e) { log.warn("Cannot Close SSH Connection"); } } }
@Override public void clear() { if (ssh != null && ssh.isConnected()) { try { ssh.disconnect(); } catch (AssertionError e) { // already connected } catch (IOException e) { logger.debug("<< exception disconnecting from %s: %s", e, e.getMessage()); } ssh = null; } }
@Override public void clear() { if (ssh != null && ssh.isConnected()) { try { ssh.disconnect(); } catch (AssertionError e) { // already connected } catch (IOException e) { logger.debug("<< exception disconnecting from %s: %s", e, e.getMessage()); } ssh = null; } }
@Override public void clear() { if (ssh != null && ssh.isConnected()) { try { ssh.disconnect(); } catch (AssertionError e) { // already connected } catch (IOException e) { logger.debug("<< exception disconnecting from %s: %s", e, e.getMessage()); } ssh = null; } }
SSHClient ssh = new SSHClient(); ssh.loadKnownHosts(); ssh.connect("your-server"); ssh.authPublickey("userId"); //START SESSION Session session = ssh.startSession(); //SEND THE COMMAND Command cmd = session.exec("shutdown"); //GET THE OUTPUT OF COMMAND cmd.getOutputAsString(); //CLOSE SESSION session.close(); ssh.disconnect();
public void testDontThrowIOExceptionOnClear() throws Exception { SshjSshClient ssh1 = createClient(); SSHClient ssh = createMock(SSHClient.class); expect(ssh.isConnected()).andReturn(true); ssh.disconnect(); expectLastCall().andThrow(new ConnectionException("disconnected")); replay(ssh); ssh1.sshClientConnection.ssh = ssh; ssh1.sshClientConnection.clear(); verify(ssh); }