Package com.jcraft.jsch

Examples of com.jcraft.jsch.JSch


            session = entry.getSession();
        }
        if (session == null || !session.isConnected()) {
            Message.verbose(":: SSH :: connecting to " + host + "...");
            try {
                JSch jsch = new JSch();
                if (port != -1) {
                    session = jsch.getSession(username, host, port);
                } else {
                    session = jsch.getSession(username, host);
                }
                if (allowedAgentUse) {
                    attemptAgentUse(jsch);
                }
                if (pemFile != null) {
                    jsch.addIdentity(pemFile.getAbsolutePath(), pemPassword);
                }
                session.setUserInfo(new CfUserInfo(host, username, userPassword, pemFile,
                        pemPassword, passFile));
                session.setDaemonThread(true);
View Full Code Here


        }
        return factory;
    }
   
    private SSHSocketImplFactory(String host) throws JSchException, IOException {
        JSch jsch = new JSch();
        jsch.setLogger(this);
        String passphrase = "";
        String defaultSSHDir = System.getProperty("user.home") + "/.ssh";
        String identityFile = defaultSSHDir + "/openid";
        String user = System.getProperty("user.name");
        user = System.getProperty("ssh.user", user);
        if (host == null) {
            throw new RuntimeException(
                    "ssh.gateway system property must be set");
        }
        String knownHosts = defaultSSHDir + "/known_hosts";
        knownHosts = System.getProperty("ssh.knownhosts", knownHosts);
        jsch.setKnownHosts(knownHosts);
        identityFile = System.getProperty("ssh.identity", identityFile);
        jsch.addIdentity(identityFile, passphrase.getBytes());
        session = jsch.getSession(user, host);
        Properties props = new Properties();
        props.put("compression.s2c", "none");
        props.put("compression.c2s", "none");
        props.put("cipher.s2c", "blowfish-cbc,3des-cbc");
        props.put("cipher.c2s", "blowfish-cbc,3des-cbc");
        if (jsch.getHostKeyRepository().getHostKey(host, null) == null) {
            // We don't have a way to prompt, so if it isn't there we want
            // it automatically added.
            props.put("StrictHostKeyChecking", "no");
        }
        session.setConfig(props);
View Full Code Here

        configureConsumer(consumer);
        return consumer;
    }

    protected Session createSession() throws JSchException {
        final JSch jsch = new JSch();
        final Session session = jsch.getSession(getConfiguration().getUsername(), getConfiguration().getHost(), getConfiguration().getPort());
        session.setUserInfo(new UserInfo() {
            public String getPassphrase() {
                return null;
            }
View Full Code Here

    final File identityFile = hc.getIdentityFile();
    if (identityFile == null)
      return defaultJSch;

    final String identityKey = identityFile.getAbsolutePath();
    JSch jsch = byIdentityFile.get(identityKey);
    if (jsch == null) {
      jsch = new JSch();
      jsch.setHostKeyRepository(defaultJSch.getHostKeyRepository());
      jsch.addIdentity(identityKey);
      byIdentityFile.put(identityKey, jsch);
    }
    return jsch;
  }
View Full Code Here

   * @return the new default JSch implementation.
   * @throws JSchException
   *             known host keys cannot be loaded.
   */
  protected JSch createDefaultJSch(FS fs) throws JSchException {
    final JSch jsch = new JSch();
    knownHosts(jsch, fs);
    identities(jsch, fs);
    return jsch;
  }
View Full Code Here

     * @throws Exception If a problem occurs.
     */
    private static String key() throws Exception {
        final ByteArrayOutputStream stream = new ByteArrayOutputStream();
        try {
            final KeyPair kpair = KeyPair.genKeyPair(new JSch(), KeyPair.DSA);
            kpair.writePublicKey(stream, "");
            kpair.dispose();
        } finally {
            stream.close();
        }
View Full Code Here

    /**
     * Creates a new connection to the server.
     */
    public static Session createConnection(String hostname, int port, char[] username, char[] password, FileSystemOptions fileSystemOptions) throws FileSystemException
    {
        JSch jsch = new JSch();

        File sshDir = null;

        // new style - user passed
        File knownHostsFile = SftpFileSystemConfigBuilder.getInstance().getKnownHosts(fileSystemOptions);
        File[] identities = SftpFileSystemConfigBuilder.getInstance().getIdentities(fileSystemOptions);

        if (knownHostsFile != null)
        {
            try
            {
                jsch.setKnownHosts(knownHostsFile.getAbsolutePath());
            }
            catch (JSchException e)
            {
                throw new FileSystemException("vfs.provider.sftp/known-hosts.error", knownHostsFile.getAbsolutePath(), e);
            }
        }
        else
        {
            if (sshDir == null)
            {
                sshDir = findSshDir();
            }
            // Load the known hosts file
            knownHostsFile = new File(sshDir, "known_hosts");
            if (knownHostsFile.isFile() && knownHostsFile.canRead())
            {
                try
                {
                    jsch.setKnownHosts(knownHostsFile.getAbsolutePath());
                }
                catch (JSchException e)
                {
                    throw new FileSystemException("vfs.provider.sftp/known-hosts.error", knownHostsFile.getAbsolutePath(), e);
                }
            }
        }

        if (identities != null)
        {
            for (int iterIdentities = 0; iterIdentities < identities.length; iterIdentities++)
            {
                final File privateKeyFile = identities[iterIdentities];
                try
                {
                    jsch.addIdentity(privateKeyFile.getAbsolutePath());
                }
                catch (final JSchException e)
                {
                    throw new FileSystemException("vfs.provider.sftp/load-private-key.error", privateKeyFile, e);
                }
            }
        }
        else
        {
            if (sshDir == null)
            {
                sshDir = findSshDir();
            }

            // Load the private key (rsa-key only)
            final File privateKeyFile = new File(sshDir, "id_rsa");
            if (privateKeyFile.isFile() && privateKeyFile.canRead())
            {
                try
                {
                    jsch.addIdentity(privateKeyFile.getAbsolutePath());
                }
                catch (final JSchException e)
                {
                    throw new FileSystemException("vfs.provider.sftp/load-private-key.error", privateKeyFile, e);
                }
            }
        }

        Session session;
        try
        {
            session = jsch.getSession(new String(username),
                    hostname,
                    port);
            if (password != null)
            {
                session.setPassword(new String(password));
View Full Code Here

        configureConsumer(consumer);
        return consumer;
    }

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

        String privateKeyFile = getConfiguration().getPrivateKeyFile();
        if (isNotNullAndNonEmpty(privateKeyFile)) {
            log.debug("Using private keyfile: " + privateKeyFile);
            String privateKeyFilePassphrase = getConfiguration().getPrivateKeyFilePassphrase();
            if (isNotNullAndNonEmpty(privateKeyFilePassphrase)) {
                jsch.addIdentity(privateKeyFile, privateKeyFilePassphrase);
            } else {
                jsch.addIdentity(privateKeyFile);
            }
        }

        String knownHostsFile = getConfiguration().getKnownHosts();
        if (isNotNullAndNonEmpty(knownHostsFile)) {
            log.debug("Using knownHosts: " + knownHostsFile);
            jsch.setKnownHosts(knownHostsFile);
        }
     
        final Session session = jsch.getSession(getConfiguration().getUsername(), getConfiguration().getHost(), getConfiguration().getPort());
        session.setUserInfo(new UserInfo() {
            public String getPassphrase() {
                return null;
            }
View Full Code Here

        sshd.start();
    }

    protected com.jcraft.jsch.Session getJschSession() throws JSchException {
        JSchLogger.init();
        JSch sch = new JSch();
        session = sch.getSession("sshd", "localhost", port);
        session.setUserInfo(new SimpleUserInfo("sshd"));
        session.connect();
        return session;
    }
View Full Code Here

    String ssh_home = SSH_HOME_DEFAULT;

    Properties props = new Properties();
    props.setProperty("StrictHostKeyChecking", "no");

    JSch jsch = new JSch();
    JSch.setConfig(props);
    /*
     * JSch.setLogger(new Logger() { public boolean isEnabled(int level) {
     * return true; }
     *
     * public void log(int level, String message) { System.out.println("JSCH
     * Level " + level + ": " + message); } });
     */

    try {
      java.io.File file;
      file = new java.io.File(ssh_home, "known_hosts"); //$NON-NLS-1$
      jsch.setKnownHosts(file.getPath());
    } catch (Exception e) {
    }

    return jsch;
  }
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.