@Test public void shouldExecuteBackgroundCommand() throws IOException { SSHClient sshClient = fixture.setupConnectedDefaultClient(); sshClient.authPassword("jeroen", "jeroen"); File file = new File(temp.getRoot(), "testdir"); assertThat("File should not exist", !file.exists()); // TODO figure out why this does not really execute in the background. Session.Command exec = sshClient.startSession().exec("mkdir " + file.getPath() + " &"); exec.join(); assertThat("File should exist", file.exists()); assertThat("File should be directory", file.isDirectory()); SFTPClient sftpClient = sshClient.newSFTPClient(); if (sftpClient.statExistence("&") != null) { sftpClient.rmdir("&"); // TODO fail here when this is fixed } } }
@Test public void shouldCorrectlyHandleSessionChannelEof() throws IOException, InterruptedException { fixture.setupConnectedDefaultClient().authPassword("jeroen", "jeroen"); Session session = fixture.getClient().startSession(); session.allocateDefaultPTY(); session.close(); Thread.sleep(1000); assertThat("Should still be connected", fixture.getClient().isConnected()); }
@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(); } }
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();
Session session = null; try { session = ssh.startSession(); if (logger.isTraceEnabled()) { logger.trace(String.format("[start SSH] %s", cmd));
@Override public Session create() throws Exception { checkConnected(); session = sshClientConnection.ssh.startSession(); session.allocatePTY("vt100", 80, 24, 0, 0, ImmutableMap.<PTYMode, Integer> of()); return session; }
@Override public Session create() throws Exception { checkConnected(); session = sshClientConnection.ssh.startSession(); session.allocatePTY("vt100", 80, 24, 0, 0, ImmutableMap.<PTYMode, Integer> of()); return session; }
@Override public Session create() throws Exception { checkConnected(); session = sshClientConnection.ssh.startSession(); session.allocatePTY("vt100", 80, 24, 0, 0, ImmutableMap.<PTYMode, Integer> of()); return session; }
@Override public Session create() throws Exception { checkConnected(); session = sshClientConnection.ssh.startSession(); session.allocatePTY("vt100", 80, 24, 0, 0, ImmutableMap.<PTYMode, Integer> of()); return session; }
@Override public Session create() throws Exception { checkConnected(); session = sshClientConnection.ssh.startSession(); session.allocatePTY("vt100", 80, 24, 0, 0, ImmutableMap.<PTYMode, Integer> of()); return session; }
@Override public Session create() throws Exception { checkConnected(); session = sshClientConnection.ssh.startSession(); if (allocatePTY) { session.allocatePTY(TERM, 80, 24, 0, 0, Collections.<PTYMode, Integer> emptyMap()); } return session; }
@Override public Session create() throws Exception { checkConnected(); session = sshClientConnection.ssh.startSession(); allocatePTY(session); return session; }
public SSHClientMocker withSession(Session session) { try { Mockito.when(client.startSession()).thenReturn(session); } catch (ConnectionException e) { } catch (TransportException e) { } return this; }
@Override public RaspiMemoryBean run() throws RaspiQueryException { LOGGER.info("Querying memory information..."); try { Session session = getSSHClient().startSession(); final Session.Command cmd = session.exec(MEMORY_INFO_CMD); cmd.join(30, TimeUnit.SECONDS); return this.formatMemoryInfo(IOUtils.readFully(cmd.getInputStream()).toString()); } catch (IOException e) { throw RaspiQueryException.createTransportFailure(e); } }
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();
@Override public Session create() throws Exception { this.sshClientConnection = acquire(SSHClientConnection.builder().fromSSHClientConnection( SshjSshClient.this.sshClientConnection).sessionTimeout(0).build()); session = sshClientConnection.startSession(); return session; }
@Override public Session create() throws Exception { this.sshClientConnection = acquire(SSHClientConnection.builder().fromSSHClientConnection( SshjSshClient.this.sshClientConnection).sessionTimeout(0).build()); session = sshClientConnection.startSession(); return session; }
@Override public Session create() throws Exception { this.sshClientConnection = acquire(SSHClientConnection.builder().fromSSHClientConnection( SshjSshClient.this.sshClientConnection).sessionTimeout(0).build()); session = sshClientConnection.startSession(); return session; }
@Override public Session create() throws Exception { this.sshClientConnection = acquire(SSHClientConnection.builder().fromSSHClientConnection( SshjSshClient.this.sshClientConnection).sessionTimeout(0).build()); session = sshClientConnection.startSession(); return session; }
@Override public Session create() throws Exception { this.sshClientConnection = acquire(SSHClientConnection.builder().fromSSHClientConnection( SshjSshClient.this.sshClientConnection).sessionTimeout(0).build()); session = sshClientConnection.startSession(); return session; }