Esempio n. 1
0
        public override Session getSession(string user, string pass, string host, int port)
        {
            OpenSshConfig.Host hc = getConfig().lookup(host);
            host = hc.getHostName();
            if (port <= 0)
            {
                port = hc.getPort();
            }
            if (user == null)
            {
                user = hc.getUser();
            }

            Session session = createSession(hc, user, host, port);

            if (pass != null)
            {
                session.setPassword(pass);
            }
            string strictHostKeyCheckingPolicy = hc.getStrictHostKeyChecking();

            //if (strictHostKeyCheckingPolicy != null)
            //    session.setConfig();
            configure(hc, session);
            return(session);
        }
 protected override void configure(OpenSshConfig.Host hc, Session session)
 {
     if (!hc.isBatchMode())
     {
         session.setUserInfo(UserInfoProvider.Provider);
     }
 }
Esempio n. 3
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        = _byIdentityFile[identityKey];

            if (jsch == null)
            {
                jsch = new JSch();
                jsch.setHostKeyRepository(def.getHostKeyRepository());
                jsch.addIdentity(identityKey);
                _byIdentityFile.Add(identityKey, jsch);
            }
            return(jsch);
        }
Esempio n. 4
0
        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);
        }
Esempio n. 5
0
        public override Session getSession(string user, string pass, string host, int port)
        {
            OpenSshConfig.Host hc = getConfig().lookup(host);
            host = hc.getHostName();
            if (port <= 0)
            {
                port = hc.getPort();
            }
            if (user == null)
            {
                user = hc.getUser();
            }

            Session session = createSession(hc, user, host, port);

            if (pass != null)
            {
                session.setPassword(pass);
            }
            string strictHostKeyCheckingPolicy = hc.getStrictHostKeyChecking();

            if (strictHostKeyCheckingPolicy != null)
            {
                var ht = new Hashtable();
                ht.put("StrictHostKeyChecking", strictHostKeyCheckingPolicy);
                session.setConfig(ht);
            }
            string pauth = hc.getPreferredAuthentications();

            if (pauth != null)
            {
                var ht = new Hashtable();
                ht.put("PreferredAuthentications", pauth);
                session.setConfig(ht);
            }
            configure(hc, session);
            return(session);
        }
 protected override void configure(OpenSshConfig.Host hc, Session session)
 {
     // No additional configuration required.
 }
Esempio n. 7
0
 protected abstract void configure(OpenSshConfig.Host hc, Session session);
Esempio n. 8
0
 protected Session createSession(OpenSshConfig.Host hc, string user, string host, int port)
 {
     return(getJSch(hc).getSession(user, host, port));
 }