net.schmizz.sshj.connection.ConnectionException Java Examples

The following examples show how to use net.schmizz.sshj.connection.ConnectionException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Main.java    From aedict with GNU General Public License v3.0 5 votes vote down vote up
private static void exec(SSHClient ssh, String cmd) throws ConnectionException, TransportException, IOException {
    final Session s = ssh.startSession();
    try {
        final Command c = s.exec(cmd);
        if (c.getExitErrorMessage() != null) {
            throw new RuntimeException("Command " + cmd + " failed to execute with status " + c.getExitStatus() + ": " + c.getExitErrorMessage() + ", " + c.getErrorAsString());
        }
    } finally {
        MiscUtils.closeQuietly(s);
    }
}
 
Example #2
Source File: SshjTool.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
protected SshAction<Session> newSessionAction() {

        return new SshAction<Session>() {

            private Session session = null;

            @Override
            public void clear() throws TransportException, ConnectionException {
                closeWhispering(session, this);
                session = null;
            }

            @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 String toString() {
                return "Session()";
            }
        };

    }
 
Example #3
Source File: SshjTool.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
@Override
public void clear() throws TransportException, ConnectionException {
    closeWhispering(session, this);
    closeWhispering(shell, this);
    closeWhispering(outgobbler, this);
    closeWhispering(errgobbler, this);
    session = null;
    shell = null;
}
 
Example #4
Source File: SshjTool.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
@Override
public void clear() throws TransportException, ConnectionException {
    closeWhispering(session, this);
    closeWhispering(shell, this);
    closeWhispering(outgobbler, this);
    closeWhispering(errgobbler, this);
    session = null;
    shell = null;
}
 
Example #5
Source File: SFTPTransfer.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Override
public KeepAlive provide(final ConnectionImpl connection) {
    return new KeepAlive(connection, "no-op-keep-alive") {
        @Override
        protected void doKeepAlive() throws TransportException, ConnectionException {
            // do nothing;
        }
    };
}
 
Example #6
Source File: VcgencmdTest.java    From rpicheck with MIT License 5 votes vote down vote up
@Test
public void vcgencmd_in_path() throws RaspiQueryException,
        ConnectionException, TransportException {
    String vcgencmdPath = "vcgencmd";
    sessionMocker.withCommand(vcgencmdPath, new CommandMocker()
            .withResponse("vcgencmd version 1.2.3.4").mock());
    sessionMocker.withCommand(vcgencmdPath + " measure_clock arm",
            new CommandMocker().withResponse("frequency(45)=840090000")
                    .mock());
    sessionMocker.withCommand(vcgencmdPath + " measure_clock core",
            new CommandMocker().withResponse("frequency(1)=320000000")
                    .mock());
    sessionMocker.withCommand(vcgencmdPath + " measure_volts core",
            new CommandMocker().withResponse("volt=1.200V").mock());
    sessionMocker.withCommand(vcgencmdPath + " measure_temp",
            new CommandMocker().withResponse("temp=41.2'C").mock());
    sessionMocker
            .withCommand(
                    vcgencmdPath + " version",
                    new CommandMocker()
                            .withResponse(
                                    "Dec 29 2014 14:23:10\nCopyright (c) 2012 Broadcom\nversion d3c15a3b57203798ff811c40ea65174834267d48 (clean) (release)")
                            .mock());
    VcgencmdBean vcgencmd = raspiQuery.queryVcgencmd();
    assertNotNull(vcgencmd);
    assertThat(vcgencmd.getArmFrequency(), CoreMatchers.is(840090000L));
    assertThat(vcgencmd.getCoreFrequency(), CoreMatchers.is(320000000L));
    assertEquals(1.200, vcgencmd.getCoreVolts(), 0.00001);
    assertEquals(41.2, vcgencmd.getCpuTemperature(), 0.00001);
}
 
Example #7
Source File: SshJClientActions.java    From cloudbreak with Apache License 2.0 4 votes vote down vote up
private static Session startSshSession(SSHClient ssh) throws ConnectionException, TransportException {
    Session sshSession = ssh.startSession();
    sshSession.allocateDefaultPTY();
    return sshSession;
}