private static void loadIdentity(SecureShell sch, FileInfo priv) { if (!priv.IsFile()) return; try { sch.AddIdentity(priv.FullName); } catch (Exception) { // Instead, pretend the key doesn't exist. } }
/// <summary> /// Obtain the JSch used to create new sessions. /// </summary> /// <param name="hc">host configuration</param> /// <returns>the JSch instance to use.</returns> protected SecureShell getJSch(OpenSshConfig.Host hc) { if (hc == null) throw new System.ArgumentNullException("hc"); SecureShell def = getDefaultJSch(); FileInfo identityFile = hc.getIdentityFile(); if (identityFile == null) return def; string identityKey = identityFile.FullName; SecureShell jsch = _byIdentityFile[identityKey]; if (jsch == null) { jsch = new SecureShell(); jsch.SetHostKeyRepository(def.GetHostKeyRepository()); jsch.AddIdentity(identityKey); _byIdentityFile.Add(identityKey, jsch); } return jsch; }