Ejemplo n.º 1
0
 private static void LoadIdentity(JSch sch, FilePath priv)
 {
     if (priv.IsFile())
     {
         try
         {
             sch.AddIdentity(priv.GetAbsolutePath());
         }
         catch (JSchException)
         {
         }
     }
 }
Ejemplo n.º 2
0
 /// <summary>Obtain the JSch used to create new sessions.</summary>
 /// <remarks>Obtain the JSch used to create new sessions.</remarks>
 /// <param name="hc">host configuration</param>
 /// <param name="fs">
 /// the file system abstraction which will be necessary to
 /// perform certain file system operations.
 /// </param>
 /// <returns>the JSch instance to use.</returns>
 /// <exception cref="NSch.JSchException">the user configuration could not be created.
 /// 	</exception>
 protected internal virtual JSch GetJSch(OpenSshConfig.Host hc, FS fs)
 {
     if (defaultJSch == null)
     {
         defaultJSch = CreateDefaultJSch(fs);
         foreach (object name in defaultJSch.GetIdentityNames())
         {
             byIdentityFile.Put((string)name, defaultJSch);
         }
     }
     FilePath identityFile = hc.GetIdentityFile();
     if (identityFile == null)
     {
         return defaultJSch;
     }
     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;
 }