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