private SshException propagate(Exception e) { throw new SshException(String.format("%s@%s:%d: Error connecting to session.", username, host, port), e); }
logger.warn(e, "<< (%s) problem using sftp [%s], attempting via sshexec", ssh.toString(), e.getMessage()); else logger.warn("<< (%s) problem using sftp [%s], attempting via sshexec", ssh.toString(), e.getMessage()); ssh.disconnect(); ssh.connect();
private void loopAndCheckSSH() throws IOException { for (int i = 0; i < 5; i++) {// retry loop TODO replace with predicate. try { checkSSH(HostAndPort.fromParts(ip.getIPAddress(), 22)); return; } catch (SshException e) { e.printStackTrace(); try { Thread.sleep(10 * 1000); } catch (InterruptedException e1) { } continue; } } }
logger.warn(e, "<< (%s) problem using sftp [%s], attempting via sshexec", ssh.toString(), e.getMessage()); else logger.warn("<< (%s) problem using sftp [%s], attempting via sshexec", ssh.toString(), e.getMessage()); ssh.disconnect(); ssh.connect();
private void loopAndCheckSSH() throws IOException { for (int i = 0; i < 5; i++) {// retry loop TODO replace with predicate. try { checkSSH(HostAndPort.fromParts(ip.getIPAddress(), 22)); return; } catch (SshException e) { e.printStackTrace(); try { Thread.sleep(10 * 1000); } catch (InterruptedException e1) { } continue; } } }
SshException propagate(Exception e, String message) { message += ": " + e.getMessage(); if (e.getMessage() != null && e.getMessage().indexOf("Auth fail") != -1) throw new AuthorizationException("(" + toString() + ") " + message, e); throw e instanceof SshException ? SshException.class.cast(e) : new SshException( "(" + toString() + ") " + message, e); }
logger.warn(e, "<< (%s) problem using sftp [%s], attempting via sshexec", ssh.toString(), e.getMessage()); else logger.warn("<< (%s) problem using sftp [%s], attempting via sshexec", ssh.toString(), e.getMessage()); ssh.disconnect(); ssh.connect();
SshException propagate(Exception e, String message) { message += ": " + e.getMessage(); if (e.getMessage() != null && e.getMessage().indexOf("Auth fail") != -1) throw new AuthorizationException("(" + toString() + ") " + message, e); throw e instanceof SshException ? SshException.class.cast(e) : new SshException( "(" + toString() + ") " + message, e); }
logger.warn(e, "<< (%s) problem using sftp [%s], attempting via sshexec", ssh.toString(), e.getMessage()); else logger.warn("<< (%s) problem using sftp [%s], attempting via sshexec", ssh.toString(), e.getMessage()); ssh.disconnect(); ssh.connect();
SshException propagate(Exception e, String message) { message += ": " + e.getMessage(); if (e.getMessage() != null && e.getMessage().indexOf("Auth fail") != -1) throw new AuthorizationException("(" + toString() + ") " + message, e); throw e instanceof SshException ? SshException.class.cast(e) : new SshException( "(" + toString() + ") " + message, e); }
@Override public void put(String path, Payload contents) { checkNotNull(path, "path"); checkNotNull(contents, "contents"); ChannelSftp sftp = getSftp(); try { sftp.put(contents.getInput(), path); } catch (SftpException e) { throw new SshException(String.format("%s@%s:%d: Error putting path: %s", username, host, port, path), e); } finally { Closeables.closeQuietly(contents); } }
private ChannelSftp getSftp() { checkConnected(); logger.debug("%s@%s:%d: Opening sftp Channel.", username, host, port); ChannelSftp sftp = null; try { sftp = (ChannelSftp) session.openChannel("sftp"); sftp.connect(); } catch (JSchException e) { throw new SshException(String.format("%s@%s:%d: Error connecting to sftp.", username, host, port), e); } return sftp; }
@VisibleForTesting SshException propagate(Exception e, String message) { message += ": " + e.getMessage(); logger.error(e, "<< " + message); if (e instanceof UserAuthException) throw new AuthorizationException("(" + toString() + ") " + message, e); throw e instanceof SshException ? SshException.class.cast(e) : new SshException( "(" + toString() + ") " + message, e); }
@VisibleForTesting SshException propagate(Exception e, String message) { message += ": " + e.getMessage(); logger.error(e, "<< " + message); if (e instanceof UserAuthException) throw new AuthorizationException("(" + toString() + ") " + message, e); throw e instanceof SshException ? SshException.class.cast(e) : new SshException( "(" + toString() + ") " + message, e); }
@VisibleForTesting SshException propagate(Exception e, String message) { message += ": " + e.getMessage(); logger.error(e, "<< " + message); if (e instanceof UserAuthException) throw new AuthorizationException("(" + toString() + ") " + message, e); throw e instanceof SshException ? SshException.class.cast(e) : new SshException( "(" + toString() + ") " + message, e); }
@VisibleForTesting SshException propagate(Exception e, String message) { message += ": " + e.getMessage(); logger.error(e, "<< " + message); if (e instanceof UserAuthException) throw new AuthorizationException("(" + toString() + ") " + message, e); throw e instanceof SshException ? SshException.class.cast(e) : new SshException( "(" + toString() + ") " + message, e); }
@VisibleForTesting SshException propagate(Exception e, String message) { message += ": " + e.getMessage(); logger.error(e, "<< " + message); if (e instanceof UserAuthException) throw new AuthorizationException("(" + toString() + ") " + message, e); throw e instanceof SshException ? SshException.class.cast(e) : new SshException( "(" + toString() + ") " + message, e); }
public Payload get(String path) { checkNotNull(path, "path"); ChannelSftp sftp = getSftp(); try { return Payloads.newInputStreamPayload(new CloseFtpChannelOnCloseInputStream(sftp.get(path), sftp)); } catch (SftpException e) { throw new SshException(String.format("%s@%s:%d: Error getting path: %s", username, host, port, path), e); } }
private void newSession() throws JSchException { JSch jsch = new JSch(); session = null; try { session = jsch.getSession(username, host, port); if (timeout != 0) session.setTimeout(timeout); logger.debug("%s@%s:%d: Session created.", username, host, port); if (password != null) { session.setPassword(password); } else { // jsch wipes out your private key jsch.addIdentity(username, Arrays.copyOf(privateKey, privateKey.length), null, emptyPassPhrase); } } catch (JSchException e) { throw new SshException(String.format("%s@%s:%d: Error creating session.", username, host, port), e); } java.util.Properties config = new java.util.Properties(); config.put("StrictHostKeyChecking", "no"); session.setConfig(config); session.connect(); logger.debug("%s@%s:%d: Session connected.", username, host, port); }
executor.setPty(true); } catch (JSchException e) { throw new SshException(String.format("%s@%s:%d: Error connecting to exec.", username, host, port), e); backoffForAttempt(++i, String.format("%s@%s:%d: bad status: -1", username, host, port)); if (errorStatus == -1) throw new SshException(String.format("%s@%s:%d: received exit status %d executing %s", username, host, port, executor.getExitStatus(), command)); return new ExecResponse(outputString, errorString, errorStatus); } catch (Exception e) { throw new SshException(String .format("%s@%s:%d: Error executing command: %s", username, host, port, command), e);