Package com.jcraft.jsch

Examples of com.jcraft.jsch.JSch


    }
   
    private Session createSession(ScpConfiguration config) {
        ObjectHelper.notNull(config, "ScpConfiguration");
        try {
            final JSch jsch = new JSch();
            // get from configuration
            if (isNotEmpty(config.getCiphers())) {
                LOG.debug("Using ciphers: {}", config.getCiphers());
                Hashtable<String, String> ciphers = new Hashtable<String, String>();
                ciphers.put("cipher.s2c", config.getCiphers());
                ciphers.put("cipher.c2s", config.getCiphers());
                JSch.setConfig(ciphers);
            }

            String knownHostsFile = config.getKnownHostsFile();
            jsch.setKnownHosts(ObjectHelper.isEmpty(knownHostsFile) ? DEFAULT_KNOWN_HOSTS : knownHostsFile);
            session = jsch.getSession(config.getUsername(), config.getHost(), config.getPort());
            session.setTimeout(config.getTimeout());
            session.setUserInfo(new SessionUserInfo(config));

            int timeout = config.getConnectTimeout();
            LOG.debug("Connecting to {} with {} timeout...", config.remoteServerInformation(),
View Full Code Here


      publicKeyPath = (publicKeyPath == null && privateKeyPath != null) ?
                privateKeyPath + ".pub" : publicKeyPath;
      if(privateKeyPath != null && publicKeyPath != null) {
        pairRepresentation = "(" + privateKeyPath + ", " +
            publicKeyPath + ")";
        KeyPair pair = KeyPair.load(new JSch(), privateKeyPath, publicKeyPath);
        if (pair.isEncrypted()) {
          throw new ConfigurationException("Key pair " + pairRepresentation +
              " is encrypted. Try generating a new passwordless SSH keypair " +
              "(e.g. with ssh-keygen).");
        }
View Full Code Here

    }
    return config;
  }

  public Session createSession() throws JSchException {
    JSch jsch = new JSch();
    if (getPrivateKeyFile() != null) {
      jsch.addIdentity(getPrivateKeyFile().getAbsolutePath());
    }
    ParsConf pars = new ParsConf();
    pars.generatePars();
    Document doc = pars.getDoc();
    int port = Integer.parseInt(doc.getElementsByTagName("port").item(0).getTextContent());
    Session session = jsch.getSession(getUsername(), getHost(), port);
    session.setConfig(getConfig());
    session.setUserInfo(getUserInfo());
    return session;
  }
View Full Code Here

    final KeyPair sshKeyPair;

    public SshContextImpl(String sshUsername, File privateKeyPath) {
        super();
        this.jsch = new JSch();

        this.sshUsername = sshUsername;
        // this.sshKey = sshKey;

        try {
View Full Code Here

  }

  private Session getSession() throws Exception {

    final JSch jsch = new JSch();

    jsch.addIdentity(keyFile.getAbsolutePath());

    final Session session = jsch.getSession(user, host, port);

    session.setConfig("StrictHostKeyChecking", "no");

    return session;
View Full Code Here

   * return a "public" -> rsa public key, "private" -> its corresponding
   *   private key
   */
  public static Map<String,String> generate() throws JSchException {
    com.jcraft.jsch.KeyPair pair = com.jcraft.jsch.KeyPair.genKeyPair(
        new JSch(),  com.jcraft.jsch.KeyPair.RSA);
    ByteArrayOutputStream publicKeyOut = new ByteArrayOutputStream();
    ByteArrayOutputStream privateKeyOut = new ByteArrayOutputStream();
    pair.writePublicKey(publicKeyOut, "whirr");
    pair.writePrivateKey(privateKeyOut);
    String publicKey = new String(publicKeyOut.toByteArray());
View Full Code Here

        return true;
    }

    protected Session createSession(final RemoteFileConfiguration configuration) throws JSchException {
        final JSch jsch = new JSch();

        SftpConfiguration sftpConfig = (SftpConfiguration) configuration;

        if (isNotEmpty(sftpConfig.getPrivateKeyFile())) {
            LOG.debug("Using private keyfile: " + sftpConfig.getPrivateKeyFile());
            if (isNotEmpty(sftpConfig.getPrivateKeyFilePassphrase())) {
                jsch.addIdentity(sftpConfig.getPrivateKeyFile(), sftpConfig.getPrivateKeyFilePassphrase());
            } else {
                jsch.addIdentity(sftpConfig.getPrivateKeyFile());
            }
        }

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

        final Session session = jsch.getSession(configuration.getUsername(), configuration.getHost(), configuration.getPort());

        if (isNotEmpty(sftpConfig.getStrictHostKeyChecking())) {
            LOG.debug("Using StrickHostKeyChecking: " + sftpConfig.getStrictHostKeyChecking());
            session.setConfig("StrictHostKeyChecking", sftpConfig.getStrictHostKeyChecking());
        }
View Full Code Here

    private final JSch jsch;
    private final Map channels;

    public SshSession(SshResourceDriver driver) {
        super(driver);
        this.jsch = new JSch();
        this.channels = Collections.synchronizedMap(new HashMap());
    }
View Full Code Here

        }

        // validate the url -- required for sftp (user and host)

        // setup a new SFTP session
        jsch = new JSch();

        // attempt to load identities from the operating system
        // find any .ssh directories we'll scan
        File[] sshDirs = findSshDirs();
        for (File sshDir : sshDirs) {
View Full Code Here

        return true;
    }

    protected Session createSession(final RemoteFileConfiguration configuration) throws JSchException {
        final JSch jsch = new JSch();
        JSch.setLogger(new JSchLogger());

        SftpConfiguration sftpConfig = (SftpConfiguration) configuration;

        if (isNotEmpty(sftpConfig.getPrivateKeyFile())) {
            LOG.debug("Using private keyfile: " + sftpConfig.getPrivateKeyFile());
            if (isNotEmpty(sftpConfig.getPrivateKeyFilePassphrase())) {
                jsch.addIdentity(sftpConfig.getPrivateKeyFile(), sftpConfig.getPrivateKeyFilePassphrase());
            } else {
                jsch.addIdentity(sftpConfig.getPrivateKeyFile());
            }
        }

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

        final Session session = jsch.getSession(configuration.getUsername(), configuration.getHost(), configuration.getPort());

        if (isNotEmpty(sftpConfig.getStrictHostKeyChecking())) {
            LOG.debug("Using StrickHostKeyChecking: " + sftpConfig.getStrictHostKeyChecking());
            session.setConfig("StrictHostKeyChecking", sftpConfig.getStrictHostKeyChecking());
        }
View Full Code Here

TOP

Related Classes of com.jcraft.jsch.JSch

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.