/// <exception cref="NGit.Errors.TransportException"></exception>
        public override RemoteSession GetSession(URIish uri, CredentialsProvider credentialsProvider
			, FS fs, int tms)
        {
            lock (this)
            {
                string user = uri.GetUser();
                string pass = uri.GetPass();
                string host = uri.GetHost();
                int port = uri.GetPort();
                try
                {
                    if (config == null)
                    {
                        config = OpenSshConfig.Get(fs);
                    }
                    OpenSshConfig.Host hc = config.Lookup(host);
                    host = hc.GetHostName();
                    if (port <= 0)
                    {
                        port = hc.GetPort();
                    }
                    if (user == null)
                    {
                        user = hc.GetUser();
                    }
                    Session session = CreateSession(credentialsProvider, fs, user, pass, host, port,
                        hc);
                    int retries = 0;
                    while (!session.IsConnected() && retries < 3)
                    {
                        try
                        {
                            retries++;
                            session.Connect(tms);
                        }
                        catch (JSchException e)
                        {
                            session.Disconnect();
                            session = null;
                            // if authentication failed maybe credentials changed at the
                            // remote end therefore reset credentials and retry
                            if (credentialsProvider != null && e.InnerException == null && e.Message.Equals("Auth fail"
                                ))
                            {
                                credentialsProvider.Reset(uri);
                                session = CreateSession(credentialsProvider, fs, user, pass, host, port, hc);
                            }
                            else
                            {
                                throw;
                            }
                        }
                    }
                    return new JschSession(session, uri);
                }
                catch (JSchException je)
                {
                    Exception c = je.InnerException;
                    if (c is UnknownHostException)
                    {
                        throw new TransportException(uri, JGitText.Get().unknownHost);
                    }
                    if (c is ConnectException)
                    {
                        throw new TransportException(uri, c.Message);
                    }
                    throw new TransportException(uri, je.Message, je);
                }
            }
        }
 /// <exception cref="NGit.Errors.TransportException"></exception>
 public override RemoteSession GetSession(URIish uri, CredentialsProvider credentialsProvider
                                          , FS fs, int tms)
 {
     lock (this)
     {
         string user = uri.GetUser();
         string pass = uri.GetPass();
         string host = uri.GetHost();
         int    port = uri.GetPort();
         try
         {
             if (config == null)
             {
                 config = OpenSshConfig.Get(fs);
             }
             OpenSshConfig.Host hc = config.Lookup(host);
             host = hc.GetHostName();
             if (port <= 0)
             {
                 port = hc.GetPort();
             }
             if (user == null)
             {
                 user = hc.GetUser();
             }
             Session session = CreateSession(credentialsProvider, fs, user, pass, host, port,
                                             hc);
             int retries = 0;
             while (!session.IsConnected() && retries < 3)
             {
                 try
                 {
                     retries++;
                     session.Connect(tms);
                 }
                 catch (JSchException e)
                 {
                     session.Disconnect();
                     session = null;
                     // if authentication failed maybe credentials changed at the
                     // remote end therefore reset credentials and retry
                     if (credentialsProvider != null && e.InnerException == null && e.Message.Equals("Auth fail"
                                                                                                     ) && retries < 3)
                     {
                         credentialsProvider.Reset(uri);
                         session = CreateSession(credentialsProvider, fs, user, pass, host, port, hc);
                     }
                     else
                     {
                         throw;
                     }
                 }
             }
             return(new JschSession(session, uri));
         }
         catch (JSchException je)
         {
             Exception c = je.InnerException;
             if (c is UnknownHostException)
             {
                 throw new TransportException(uri, JGitText.Get().unknownHost);
             }
             if (c is ConnectException)
             {
                 throw new TransportException(uri, c.Message);
             }
             throw new TransportException(uri, je.Message, je);
         }
     }
 }