Package com.jcraft.jsch

Examples of com.jcraft.jsch.JSchException


      assert !ssh.shouldRetry(new SftpException(ChannelSftp.SSH_FX_FAILURE, new NullPointerException().toString()));
   }

   public void testCausalChainHasMessageContaining() {
      assert ssh.causalChainHasMessageContaining(
            new JSchException("Session.connect: java.io.IOException: End of IO Stream Read")).apply(
            " End of IO Stream Read");
      assert ssh.causalChainHasMessageContaining(new JSchException("Session.connect: invalid data")).apply(
            " invalid data");
      assert ssh.causalChainHasMessageContaining(
            new JSchException("Session.connect: java.net.SocketException: Connection reset")).apply("java.net.Socket");
      assert !ssh.causalChainHasMessageContaining(new NullPointerException()).apply(" End of IO Stream Read");
   }
View Full Code Here


            } catch (SftpException ee) {
                // Ignored
            }
            getDir(channel, remoteFile, localFile);
        } catch (SftpException e) {
            JSchException schException = new JSchException("Could not get '"+ remoteFile
                    +"' to '"+localFile+"' - "
                    +e.toString());
            schException.initCause(e);
            throw schException;
        } finally {
            if (channel != null) {
                channel.disconnect();
            }
View Full Code Here

      context.requestAnonymity(false);

      return;
    }
    catch(GSSException ex){
      throw new JSchException(ex.toString());
    }
  }
View Full Code Here

        setSystemProperty(pUseSubjectCredsOnly, "false");
      }
      return context.initSecContext(token, 0, l);
    }
    catch(GSSException ex){
      throw new JSchException(ex.toString());
    }
    catch(java.lang.SecurityException ex){
      throw new JSchException(ex.toString());
    }
    finally{
      if(useSubjectCredsOnly==null){
        // By the default, it must be "true".
        setSystemProperty(pUseSubjectCredsOnly, "true");
View Full Code Here

            } catch (SftpException ee) {
                // Ignored
            }
            getDir(channel, remoteFile, localFile);
        } catch (SftpException e) {
            JSchException schException = new JSchException("Could not get '"+ remoteFile
                    +"' to '"+localFile+"' - "
                    +e.toString());
            schException.initCause(e);
            throw schException;
        } finally {
            if (channel != null) {
                channel.disconnect();
            }
View Full Code Here

        channel.connect();
        try {
            fileAttributes = channel.lstat(remoteDir(remoteFile)
                                           + localFile.getName());
        } catch (SftpException e) {
            throw new JSchException("failed to stat remote file", e);
        }
        FileUtils.getFileUtils().setFileLastModified(localFile,
                                                     ((long) fileAttributes
                                                      .getMTime())
                                                     * 1000);
 
View Full Code Here

        try {
            channel.connect();
            try {
                sendFileToRemote(channel, localFile, remotePath);
            } catch (SftpException e) {
                JSchException schException = new JSchException("Could not send '" + localFile
                        + "' to '" + remotePath + "' - "
                        + e.toString());
                schException.initCause(e);
                throw schException;
            }
        } finally {
            if (channel != null) {
                channel.disconnect();
View Full Code Here

                } catch (SftpException e) {
                    if (e.id == ChannelSftp.SSH_FX_NO_SUCH_FILE) {
                        // dir does not exist.
                        channel.mkdir(remotePath);
                    } else {
                        throw new JSchException("failed to access remote dir '"
                                                + remotePath + "'", e);
                    }
                }
                channel.cd(remotePath);
            } catch (SftpException e) {
                throw new JSchException("Could not CD to '" + remotePath
                                        + "' - " + e.toString(), e);
            }
            Directory current = null;
            try {
                for (Iterator i = directoryList.iterator(); i.hasNext();) {
                    current = (Directory) i.next();
                    if (getVerbose()) {
                        log("Sending directory " + current);
                    }
                    sendDirectory(channel, current);
                }
            } catch (SftpException e) {
                String msg = "Error sending directory";
                if (current != null && current.getDirectory() != null) {
                    msg += " '" + current.getDirectory().getName() + "'";
                }
                throw new JSchException(msg, e);
            }
        } finally {
            if (channel != null) {
                channel.disconnect();
            }
View Full Code Here

            byte[] passphrase = null;
            if (isNotEmpty(sftpConfig.getPrivateKeyPassphrase())) {
                try {
                    passphrase = sftpConfig.getPrivateKeyPassphrase().getBytes("UTF-8");
                } catch (UnsupportedEncodingException e) {
                    throw new JSchException("Cannot transform passphrase to byte[]", e);
                }
            }
            jsch.addIdentity("ID", sftpConfig.getPrivateKey(), null, passphrase);
        }

        if (sftpConfig.getPrivateKeyUri() != null) {
            LOG.debug("Using private key uri : {}", sftpConfig.getPrivateKeyUri());
            byte[] passphrase = null;
            if (isNotEmpty(sftpConfig.getPrivateKeyPassphrase())) {
                try {
                    passphrase = sftpConfig.getPrivateKeyPassphrase().getBytes("UTF-8");
                } catch (UnsupportedEncodingException e) {
                    throw new JSchException("Cannot transform passphrase to byte[]", e);
                }
            }
            try {
                InputStream is = ResourceHelper.resolveMandatoryResourceAsInputStream(endpoint.getCamelContext().getClassResolver(), sftpConfig.getPrivateKeyUri());
                ByteArrayOutputStream bos = new ByteArrayOutputStream();
                IOHelper.copyAndCloseInput(is, bos);
                jsch.addIdentity("ID", bos.toByteArray(), null, passphrase);
            } catch (IOException e) {
                throw new JSchException("Cannot read resource: " + sftpConfig.getPrivateKeyUri(), e);
            }
        }

        if (isNotEmpty(sftpConfig.getKnownHostsFile())) {
            LOG.debug("Using knownhosts file: {}", sftpConfig.getKnownHostsFile());
            jsch.setKnownHosts(sftpConfig.getKnownHostsFile());
        }

        if (isNotEmpty(sftpConfig.getKnownHostsUri())) {
            LOG.debug("Using knownhosts uri: {}", sftpConfig.getKnownHostsUri());
            try {
                InputStream is = ResourceHelper.resolveMandatoryResourceAsInputStream(endpoint.getCamelContext().getClassResolver(), sftpConfig.getKnownHostsUri());
                jsch.setKnownHosts(is);
            } catch (IOException e) {
                throw new JSchException("Cannot read resource: " + sftpConfig.getKnownHostsUri(), e);
            }
        }

        if (sftpConfig.getKnownHosts() != null) {
            LOG.debug("Using knownhosts information from byte array");
View Full Code Here

   * @throws IOException
   */
  private static List<FileInfo> getMatchingRemoteFileList(SSHCommand sshCommand, String remoteDirPath, String baseName) throws JSchException, IOException
  {
    if ((sshCommand == null) || !sshCommand.isConnected()) {
      throw new JSchException("Not connected with a valid SSH session");
    }
    String remoteUsername = null;
    if (LogCollector.collectOnlyUserOwnedLogs) {
      remoteUsername = sshCommand.getSessionUsername();
      if (remoteUsername == null) {
        throw new JSchException("Username for SSH session is not valid")
      }
    }
    // First get a list of *all* files in the remote directory, and then
    // parse the results for a match with the target basename
    // (Prefer to do the matching work locally rather than remotely)
View Full Code Here

TOP

Related Classes of com.jcraft.jsch.JSchException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.