Package com.jcraft.jsch

Examples of com.jcraft.jsch.Session


     *
     * @see org.apache.ivy.repository.Repository#put(java.io.File, java.lang.String, boolean)
     */
    public void put(File source, String destination, boolean overwrite) throws IOException {
        Message.debug("SShRepository:put called: " + destination);
        Session session = getSession(destination);

        URI destinationUri = null;
        try {
            destinationUri = new URI(destination);
        } catch (URISyntaxException e) {
View Full Code Here


        Message.debug("SShRepository:get called: " + source + " to "
                + destination.getCanonicalPath());
        if (destination.getParentFile() != null) {
            destination.getParentFile().mkdirs();
        }
        Session session = getSession(source);

        URI sourceUri = null;
        try {
            sourceUri = new URI(source);
        } catch (URISyntaxException e) {
View Full Code Here

     * @param resource
     *            to stream
     * @return InputStream of the resource data
     */
    public InputStream openStream(SshResource resource) throws IOException {
        Session session = getSession(resource.getName());
        Scp scp = new Scp(session);
        ByteArrayOutputStream os = new ByteArrayOutputStream();
        try {
            scp.get(resource.getName(), os);
        } catch (IOException e) {
View Full Code Here

     * @return the ChannelSftp with which a connection is established
     * @throws IOException
     *             if any connection problem occurs
     */
    private ChannelSftp getSftpChannel(String pathOrUri) throws IOException {
        Session session = getSession(pathOrUri);
        String host = session.getHost();
        ChannelSftp channel = SshCache.getInstance().getChannelSftp(session);
        if (channel == null) {
            try {
                channel = (ChannelSftp) session.openChannel("sftp");
                channel.connect();
                Message.verbose(":: SFTP :: connected to " + host + "!");
                SshCache.getInstance().attachChannelSftp(session, channel);
            } catch (JSchException e) {
                IOException ex = new IOException(e.getMessage());
View Full Code Here

        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;
            }

            public String getPassword() {
View Full Code Here

      if (port <= 0)
        port = hc.getPort();
      if (user == null)
        user = hc.getUser();

      Session session = createSession(credentialsProvider, fs, user,
          pass, host, port, hc);

      int retries = 0;
      while (!session.isConnected() && retries < 3) {
        try {
          retries++;
          session.connect(tms);
        } catch (JSchException e) {
          session.disconnect();
          session = null;
          // if authentication failed maybe credentials changed at the
          // remote end therefore reset credentials and retry
          if (credentialsProvider != null && e.getCause() == null
              && e.getMessage().equals("Auth fail")) {
View Full Code Here

  }

  private Session createSession(CredentialsProvider credentialsProvider,
      FS fs, String user, final String pass, String host, int port,
      final OpenSshConfig.Host hc) throws JSchException {
    final Session session = createSession(hc, user, host, port, fs);
    if (pass != null)
      session.setPassword(pass);
    final String strictHostKeyCheckingPolicy = hc
        .getStrictHostKeyChecking();
    if (strictHostKeyCheckingPolicy != null)
      session.setConfig("StrictHostKeyChecking",
          strictHostKeyCheckingPolicy);
    final String pauth = hc.getPreferredAuthentications();
    if (pauth != null)
      session.setConfig("PreferredAuthentications", pauth);
    if (credentialsProvider != null
        && (!hc.isBatchMode() || !credentialsProvider.isInteractive())) {
      session.setUserInfo(new CredentialsProviderUserInfo(session,
          credentialsProvider));
    }
    configure(hc, session);
    return session;
  }
View Full Code Here

        // JSch jsch = createJSch(fileSystemOptions);

        // Create the file system
        final GenericFileName rootName = (GenericFileName) name;

        Session session;
    UserAuthenticationData authData = null;
        try
        {
      authData = UserAuthenticatorUtils.authenticate(fileSystemOptions, AUTHENTICATOR_TYPES);
View Full Code Here

    protected ChannelSftp getChannel() throws IOException
    {
        if (this.session == null)
        {
            // channel closed. e.g. by freeUnusedResources, but now we need it again
            Session session;
      UserAuthenticationData authData = null;
      try
            {
                final GenericFileName rootName = (GenericFileName) getRootName();

        authData = UserAuthenticatorUtils.authenticate(getFileSystemOptions(), SftpFileProvider.AUTHENTICATOR_TYPES);

        session = SftpClientFactory.createConnection(
          rootName.getHostName(),
          rootName.getPort(),
          UserAuthenticatorUtils.getData(authData, UserAuthenticationData.USERNAME, UserAuthenticatorUtils.toChar(rootName.getUserName())),
          UserAuthenticatorUtils.getData(authData, UserAuthenticationData.PASSWORD, UserAuthenticatorUtils.toChar(rootName.getPassword())),
          getFileSystemOptions());
            }
            catch (final Exception e)
            {
                throw new FileSystemException("vfs.provider.sftp/connect.error",
                    getRootName(),
                    e);
            }
      finally
      {
        UserAuthenticatorUtils.cleanup(authData);
      }

      this.session = session;
        }

        try
        {
            // Use the pooled channel, or create a new one
            final ChannelSftp channel;
            if (idleChannel != null)
            {
                channel = idleChannel;
                idleChannel = null;
            }
            else
            {
                channel = (ChannelSftp) session.openChannel("sftp");
                channel.connect();

                Boolean userDirIsRoot = SftpFileSystemConfigBuilder.getInstance().getUserDirIsRoot(getFileSystemOptions());
                String workingDirectory = getRootName().getPath();
                if (workingDirectory != null && (userDirIsRoot == null || !userDirIsRoot.booleanValue()))
View Full Code Here

                    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));
            }

            Integer timeout = SftpFileSystemConfigBuilder.getInstance().getTimeout(fileSystemOptions);
            if (timeout != null)
            {
              session.setTimeout(timeout.intValue());
            }

            UserInfo userInfo = SftpFileSystemConfigBuilder.getInstance().getUserInfo(fileSystemOptions);
            if (userInfo != null)
            {
                session.setUserInfo(userInfo);
            }

            Properties config = new Properties();

            //set StrictHostKeyChecking property
            String strictHostKeyChecking = SftpFileSystemConfigBuilder.getInstance().getStrictHostKeyChecking(fileSystemOptions);
            if (strictHostKeyChecking != null)
            {
                config.setProperty("StrictHostKeyChecking", strictHostKeyChecking);
            }

            //set compression property
            String compression = SftpFileSystemConfigBuilder.getInstance().getCompression(fileSystemOptions);
            if (compression != null)
            {
                config.setProperty("compression.s2c", compression);
                config.setProperty("compression.c2s", compression);
            }

            String proxyHost = SftpFileSystemConfigBuilder.getInstance().getProxyHost(fileSystemOptions);
            if (proxyHost != null)
            {
                int proxyPort = SftpFileSystemConfigBuilder.getInstance().getProxyPort(fileSystemOptions);
                SftpFileSystemConfigBuilder.ProxyType proxyType = SftpFileSystemConfigBuilder.getInstance().getProxyType(fileSystemOptions);
                Proxy proxy = null;
                if (SftpFileSystemConfigBuilder.PROXY_HTTP.equals(proxyType))
                {
                    if (proxyPort != 0)
                    {
                        proxy = new ProxyHTTP(proxyHost, proxyPort);
                    }
                    else
                    {
                        proxy = new ProxyHTTP(proxyHost);
                    }
                }
                else if (SftpFileSystemConfigBuilder.PROXY_SOCKS5.equals(proxyType))
                {
                    if (proxyPort != 0)
                    {
                        proxy = new ProxySOCKS5(proxyHost, proxyPort);
                    }
                    else
                    {
                        proxy = new ProxySOCKS5(proxyHost);
                    }
                }

                if (proxy != null)
                {
                    session.setProxy(proxy);
                }
            }

            //set properties for the session
            if (config.size() > 0)
            {
                session.setConfig(config);
            }

            session.connect();
        }
        catch (final Exception exc)
        {
            throw new FileSystemException("vfs.provider.sftp/connect.error", new Object[]{hostname}, exc);
        }
View Full Code Here

TOP

Related Classes of com.jcraft.jsch.Session

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.