commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From adammurd...@apache.org
Subject cvs commit: jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/provider/sftp SftpFileProvider.java
Date Tue, 24 Jun 2003 10:37:11 GMT
adammurdoch    2003/06/24 03:37:11

  Modified:    vfs/src/java/org/apache/commons/vfs/provider/sftp
                        SftpFileProvider.java
  Log:
  Add support to SftpFileProvider for loading the user's private key.
  
  Patch submitted by Steve ?
  
  Revision  Changes    Path
  1.2       +27 -6     jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/provider/sftp/SftpFileProvider.java
  
  Index: SftpFileProvider.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/provider/sftp/SftpFileProvider.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- SftpFileProvider.java	20 Feb 2003 07:30:36 -0000	1.1
  +++ SftpFileProvider.java	24 Jun 2003 10:37:11 -0000	1.2
  @@ -62,6 +62,8 @@
   import org.apache.commons.vfs.provider.AbstractOriginatingFileProvider;
   import org.apache.commons.vfs.provider.GenericFileName;
   import com.jcraft.jsch.JSch;
  +import com.jcraft.jsch.JSchException;
  +import java.io.File;
   
   /**
    * A provider for accessing files over SFTP.
  @@ -79,20 +81,39 @@
        */
       public void init() throws FileSystemException
       {
  -        // Figure out where the known_hosts file is
  -        final String knownHostsPath;
  +        // Figure out where the ssh directory is
  +        final File sshDir;
           if ( Os.isFamily( Os.OS_FAMILY_WINDOWS ) )
           {
               // TODO - this may not be true
               final String userName = System.getProperty( "user.name" );
  -            knownHostsPath = "C:\\cygwin\\home\\" + userName + "\\.ssh\\known_hosts";
  +            sshDir = new File("C:\\cygwin\\home\\" + userName + "\\.ssh" );
           }
           else
           {
  -            knownHostsPath = System.getProperty( "user.home") + "/.ssh/known_hosts";
  +            sshDir = new File( System.getProperty( "user.home" ), ".ssh" );
           }
   
  -        jSch.setKnownHosts( knownHostsPath );
  +        // Load the known hosts file
  +        final File knownHostsFile = new File(sshDir, "known_hosts");
  +        if ( knownHostsFile.isFile() && knownHostsFile.canRead() )
  +        {
  +            jSch.setKnownHosts( knownHostsFile.getAbsolutePath() );
  +        }
  +
  +        // Load the private key
  +        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);
  +            }
  +        }
       }
   
       /**
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message