net.schmizz.sshj.transport.TransportException Java Examples

The following examples show how to use net.schmizz.sshj.transport.TransportException. 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: SFTPExceptionMappingService.java    From cyberduck with GNU General Public License v3.0 6 votes vote down vote up
public BackgroundException map(final IOException e, final StringBuilder buffer, final DisconnectReason reason) {
    final String failure = buffer.toString();
    if(DisconnectReason.HOST_KEY_NOT_VERIFIABLE.equals(reason)) {
        log.warn(String.format("Failure verifying host key. %s", failure));
        // Host key dismissed by user
        return new ConnectionCanceledException(e);
    }
    if(DisconnectReason.PROTOCOL_ERROR.equals(reason)) {
        // Too many authentication failures
        return new InteroperabilityException(failure, e);
    }
    if(DisconnectReason.ILLEGAL_USER_NAME.equals(reason)) {
        return new LoginFailureException(failure, e);
    }
    if(DisconnectReason.NO_MORE_AUTH_METHODS_AVAILABLE.equals(reason)) {
        return new LoginFailureException(failure, e);
    }
    if(DisconnectReason.PROTOCOL_VERSION_NOT_SUPPORTED.equals(reason)) {
        return new InteroperabilityException(failure, e);
    }
    if(e instanceof TransportException) {
        return new ConnectionRefusedException(buffer.toString(), e);
    }
    return this.wrap(e, buffer);
}
 
Example #2
Source File: TestChrootSFTPClient.java    From datacollector with Apache License 2.0 6 votes vote down vote up
@Test
public void testSetSFTPClient() throws Exception {
  path = testFolder.getRoot().getAbsolutePath();
  setupSSHD(path);
  SSHClient sshClient = createSSHClient();
  ChrootSFTPClient sftpClient = new ChrootSFTPClient(sshClient.newSFTPClient(), path, false, false, false);

  sftpClient.ls();
  // Close the SSH client so it's no longer usable and the SFTP client will get an exception
  sshClient.close();
  try {
    sftpClient.ls();
    Assert.fail("Expected a TransportException");
  } catch (TransportException se) {
    Assert.assertEquals("Socket closed", se.getMessage());
  }
  // Set a new SSH client and try again
  sftpClient.setSFTPClient(createSSHClient().newSFTPClient());
  sftpClient.ls();
}
 
Example #3
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 #4
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 #5
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 #6
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 #7
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 #8
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 #9
Source File: ConnectAndAuthTest.java    From rpicheck with MIT License 5 votes vote down vote up
@Test(expected = RaspiQueryException.class)
public void connect_auth_failure() throws RaspiQueryException,
        UserAuthException, TransportException {
    Mockito.doThrow(UserAuthException.class).when(sshClient)
            .authPassword(Mockito.anyString(), Mockito.anyString());
    raspiQuery.connect("wrong_pw");
}
 
Example #10
Source File: SFTPExceptionMappingServiceTest.java    From cyberduck with GNU General Public License v3.0 4 votes vote down vote up
@Test
public void testWrapped() {
    assertEquals(InteroperabilityException.class,
        new SFTPExceptionMappingService().map(new TransportException(DisconnectReason.UNKNOWN, new SSHException(DisconnectReason.PROTOCOL_ERROR))).getClass());
}
 
Example #11
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;
}