isConnected() public method

public isConnected ( ) : bool
return bool
示例#1
0
 public void Connect()
 {
     InitVAHInfo();
     try
     {
         JSch jsch = new JSch();
         _ssn = jsch.getSession(_usr, _hip, _hp);
         System.Collections.Hashtable hashConfig = new Hashtable();
         hashConfig.Add("StrictHostKeyChecking", "No");
         _ssn.setConfig(hashConfig);
         jsch.addIdentity(_ppk);
         _ssn.connect();
         if (_ssn.isConnected())
         {
             Console.WriteLine("Log Successfully.");
         }
         else
         {
             Console.WriteLine("Log failed.");
         }
     }
     catch (Tamir.SharpSsh.jsch.JSchException jschex)
     {
         Console.WriteLine(jschex.Message);
     }
     catch (Exception anyex)
     {
         Console.WriteLine(anyex.Message);
     }
 }
示例#2
0
        public void releaseSession(Session session)
        {
            if (session == null)
                throw new System.ArgumentNullException ("session");

            if (session.isConnected())
                session.disconnect();
        }
示例#3
0
        protected override void OnStart(string[] args)
        {
            bool ontWorkerInstantiated = false;

            if (Repository.Configuration.Processes == null)
                return;

            if (Repository.Configuration.Database.SSH.Enabled)
            {
                try
                {
                    //Create a new SSH session
                    _jsch = new JSch();
                    _sshSession = _jsch.getSession(
                        Repository.Configuration.Database.SSH.UserID,
                        Repository.Configuration.Database.SSH.Host,
                        Repository.Configuration.Database.SSH.Port);

                    _sshSession.setHost(Repository.Configuration.Database.SSH.Host);
                    _sshSession.setPassword(Repository.Configuration.Database.SSH.Password);

                    UserInfo ui = new JschUserInfo();
                    _sshSession.setUserInfo(ui);

                    // Connect
                    _sshSession.connect();

                    //Set port forwarding on the opened session
                    _sshSession.setPortForwardingL(
                        Repository.Configuration.Database.SSH.LocalPort,
                        Repository.Configuration.Database.SSH.ForwardingHost,
                        Repository.Configuration.Database.SSH.RemotePort);

                    if (!_sshSession.isConnected())
                        throw new Exception("SSH Session did not connect.");
                }
                catch (Exception ex)
                {
                    EventLogWriter.WriteError("Could not start due to SSH Error:\n{0}", ex);
                    return;
                }
            }

            foreach (TextMinerServiceSettingsProcess process in Repository.Configuration.Processes)
            {
                if (!process.Enabled)
                    continue;

                switch (process.Type)
                {
                    case ProcessType.OntologySubsetWorker:
                        {
                            // Only one thread of this type allowed
                            if (ontWorkerInstantiated == true)
                                continue;

                            process.Worker = new Worker.OntologySubset(process.PollingInterval, process.Timeout, process.ResponseTimeout);
                            ontWorkerInstantiated = true;
                            break;
                        }
                    case ProcessType.PubMed:
                        {
                            process.Worker = new Worker.PubMed(process.PollingInterval, process.Timeout, process.PostPollingInterval, process.ResponseTimeout, process.OntogratorTab);
                            break;
                        }
                    case ProcessType.Pubget:
                        {
                            process.Worker = new Worker.Pubget(process.PollingInterval, process.Timeout, process.PostPollingInterval, process.ResponseTimeout, process.OntogratorTab);
                            break;
                        }
                    case ProcessType.ClinicalTrialsGov:
                        {
                            process.Worker = new Worker.ClinicalTrialsGov(process.PollingInterval, process.Timeout, process.PostPollingInterval, process.ResponseTimeout, process.OntogratorTab);
                            break;
                        }
                    default:
                        {
                            continue;
                        }
                }

                process.Thread = new Thread(new ThreadStart(process.Worker.Start));
                process.Thread.Start();
            }
        }
示例#4
0
        public static void Connect()
        {
            try
             {
                 var jsch = new JSch();

                 _session = jsch.getSession(Settings.SSHUsername, Settings.SSHHost, Settings.SSHPort);
                 _session.setHost(Settings.SSHHost);
                 _session.setPassword(Settings.SSHPassword);
                 UserInfo ui = new MyUserInfo(Settings.SSHPassword);
                 _session.setUserInfo(ui);
                 _session.connect();
                 int port;
                 if (!int.TryParse(Settings.Port, out port))
                     port = 3306;
                 _session.setPortForwardingL(Settings.SSHLocalPort, "localhost", port);
                 if (!_session.isConnected())
                    Enabled = false;
             }
             catch (Exception ex)
             {
                Enabled = false;
                Trace.WriteLine(ex.Message + " at ssh connect.");
                Disconnect();
            }
        }
        protected void OpenSSH()
        {
            try
            {
                //Create a new SSH session
                _jsch = new JSch();
                _sshSession = _jsch.getSession(
                    Settings.SSHUserID,
                    Settings.SSHHost,
                    int.Parse(Settings.SSHPort));

                _sshSession.setHost(Settings.SSHHost);
                _sshSession.setPassword(Settings.SSHPassword);

                UserInfo ui = new JschUserInfo();
                _sshSession.setUserInfo(ui);

                // Connect
                _sshSession.connect();

                //Set port forwarding on the opened session
                _sshSession.setPortForwardingL(
                    int.Parse(Settings.SSHLocalPort),
                    Settings.SSHForwardingHost,
                    int.Parse(Settings.SSHRemotePort));

                if (!_sshSession.isConnected())
                    throw new Exception("SSH Session did not connect.");
            }
            catch (Exception ex)
            {
                MessageBox.Show(string.Format("Could not start due to SSH Error:\n{0}", ex));
                return;
            }
        }
示例#6
0
 public void releaseSession(Session session)
 {
     if (session.isConnected())
         session.disconnect();
 }
示例#7
0
        /// <summary>
        /// Initialize SSH session
        /// </summary>
        protected void InitSession()
        {
            if (_sock != null) return;

            int tms = Timeout > 0 ? Timeout * 1000 : 0;
            string user = Uri.User;
            string pass = Uri.Pass;
            string host = Uri.Host;
            int port = Uri.Port;
            try
            {
                _sock = _sch.getSession(user, pass, host, port);
                if (!_sock.isConnected())
                {
                    _sock.connect(tms);
                }
            }
            catch (JSchException je)
            {
                throw new TransportException(Uri, je.Message, je.InnerException);
            }
            catch (SocketException e)
            {
                throw new TransportException(e.Message, e.InnerException ?? e);
            }
        }