/// <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); }
private static void LoadIdentity(JSch sch, FilePath priv) { if (priv.IsFile()) { try { sch.AddIdentity(priv.GetAbsolutePath()); } catch (JSchException) { } } }
/// <exception cref="Com.Jcraft.Jsch.JSchException"/> private Session CreateSession(string host, SshFenceByTcpPort.Args args) { JSch jsch = new JSch(); foreach (string keyFile in GetKeyFiles()) { jsch.AddIdentity(keyFile); } JSch.SetLogger(new SshFenceByTcpPort.LogAdapter()); Session session = jsch.GetSession(args.user, host, args.sshPort); session.SetConfig("StrictHostKeyChecking", "no"); return(session); }