setHostKeyRepository() public method

public setHostKeyRepository ( Tamir.SharpSsh.jsch.HostKeyRepository foo ) : void
foo Tamir.SharpSsh.jsch.HostKeyRepository
return void
Exemplo n.º 1
0
        /// <summary>
        /// Obtain the JSch used to create new sessions.
        /// </summary>
        /// <param name="hc">host configuration</param>
        /// <returns>the JSch instance to use.</returns>
        protected JSch getJSch(OpenSshConfig.Host hc)
        {
            if (hc == null)
                throw new System.ArgumentNullException("hc");

            JSch def = getDefaultJSch();
            FileInfo identityFile = hc.getIdentityFile();
            if (identityFile == null)
                return def;

            string identityKey = identityFile.FullName;
            JSch jsch;
            if(!_byIdentityFile.TryGetValue(identityKey, out jsch))
            {
                jsch = new JSch();
                jsch.setHostKeyRepository(def.getHostKeyRepository());
                jsch.addIdentity(identityKey);
                _byIdentityFile.Add(identityKey, jsch);
            }
            return jsch;
        }
        protected JSch getJSch(OpenSshConfig.Host hc)
        {
            JSch def = getDefaultJSch();
            FileInfo identityFile = hc.getIdentityFile();
            if (identityFile == null)
                return def;

            string identityKey = Path.GetFullPath(identityFile.ToString());
            JSch jsch = byIdentityFile[identityKey];
            if (jsch == null)
            {
                jsch = new JSch();
                jsch.setHostKeyRepository(def.getHostKeyRepository());
                jsch.addIdentity(identityKey);
                byIdentityFile.Add(identityKey, jsch);
            }
            return jsch;
        }