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); } }
/// <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); }
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); }
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. }
protected abstract void configure(OpenSshConfig.Host hc, Session session);
protected Session createSession(OpenSshConfig.Host hc, string user, string host, int port) { return(getJSch(hc).getSession(user, host, port)); }