setUserInfo() public method

public setUserInfo ( UserInfo userinfo ) : void
userinfo UserInfo
return void
Esempio n. 1
0
        //Host: SFTP: nombre de usuario contraseña de usuario: Dirección de pwd

        public SFTPHelper(string host, string user, string pwd)
        {
            string[] arr = host.Split(':');

            string ip = arr[0];

            int port = 22;

            if (arr.Length > 1)
            {
                port = Int32.Parse(arr[1]);
            }



            JSch jsch = new JSch();

            m_session = jsch.getSession(user, ip, port);

            MyUserInfo ui = new MyUserInfo();

            ui.setPassword(pwd);

            m_session.setUserInfo(ui);
        }
Esempio n. 2
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();
            }
        }
Esempio n. 3
0
 /// <summary>
 /// 构造方法
 /// </summary>
 /// <param name="host"></param>
 /// <param name="user"></param>
 /// <param name="pwd"></param>
 public SftpHelper(string host, string user, string pwd)
 {
     string[] arr = host.Split(':');
     string ip = arr[0];
     int port = 22;
     if (arr.Length > 1) port = Int32.Parse(arr[1]);
     JSch jsch = new JSch();
     m_session = jsch.getSession(user, ip, port);
     MyUserInfo ui = new MyUserInfo();
     ui.setPassword(pwd);
     m_session.setUserInfo(ui);
 }
Esempio n. 4
0
		protected void _Connect()
		{
			_jsch = new JSch();
			//session.setConfig();
			_session = _jsch.getSession(this.Username, this.Host, this.Port);
			UserInfo ui = new DirectPasswordUserInfo(this.Password);
			_session.setUserInfo(ui);
			_session.connect();

			_csftp = (ChannelSftp)_session.openChannel("sftp");
			_csftp.connect();

			//RootPath = csftp.getHome();
			RootPath = "";
		}
Esempio n. 5
0
        /// <summary>
        ///  This class creates a jsch instance using the host that user wants. This makes it possible to
        ///  forward the MySql Database port to a user's local port.
        /// </summary>
        public string jschServer(string host, string user, string password)
        {
            try
            {
                // Create a new JSch instance
                JSch jsch = new JSch();

                // Saves the info to make other sessions
                this.host = host;
                this.user = user;
                this.password = password;

                // Create a new SSH session
                session = jsch.getSession(user, password, port);
                session.setHost(host); ;
                session.setPassword(password);

                // Creates a userinfo instance to pass into the session
                UserInfo ui = new MyUserInfo();
                session.setUserInfo(ui);

                session.connect();

                return null;
            }
            catch (Exception ex)
            {
                session.disconnect();
                return ex.Message;
            }
        }
Esempio n. 6
0
		protected virtual void ConnectSession(int tcpPort)
		{
			m_session = m_jsch.getSession(m_user, m_host, tcpPort);
			if (Password != null)
				m_session.setUserInfo(new KeyboardInteractiveUserInfo(Password));
			Hashtable config = new Hashtable();
			config.Add("StrictHostKeyChecking", "no");
			m_session.setConfig(config);
			m_session.connect();
		}
Esempio n. 7
0
        internal bool SSHConnect()
        {
            try
            {
                channels_ = new Dictionary<int, ChannelSftp>();

                jsch_ = new JSch();
                Hashtable config = new Hashtable();
                config["StrictHostKeyChecking"] = "no";

                if (identity_ != null)
                    jsch_.addIdentity(identity_, passphrase_);

                session_ = jsch_.getSession(user_, host_, port_);
                session_.setConfig(config);
                session_.setUserInfo(new DokanUserInfo(password_, passphrase_));
                session_.setPassword(password_);

                session_.connect();

                return true;
            }
            catch (Exception e)
            {
                Debug(e.ToString());
                return false;
            }
        }
Esempio n. 8
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();
            }
        }
Esempio n. 9
0
        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;
            }
        }
Esempio n. 10
0
        public static bool Connect(string thost,string tuser,string tpass,string tport)
        {
            try
            {
                JSch jsch = new JSch();
                host = thost;
                user = tuser;
                pass = tpass;
                sshPort = Convert.ToInt32(tport);

                session = jsch.getSession(user, host, sshPort);
                session.setHost(host);
                session.setPassword(pass);
                UserInfo ui = new MyUserInfo();
                session.setUserInfo(ui);
                session.connect();
                session.setPortForwardingL(lPort, "127.0.0.1", rPort);
                return true;
            }
            catch (Exception ex)
            {
                error = ex;
                return false;
            }
        }
Esempio n. 11
0
        protected virtual void ConnectSession(int tcpPort)
        {
            m_session = m_jsch.getSession(m_user, m_host, tcpPort);

            if (Password != null)
            {
                if (m_userInfo == null)
                    m_userInfo = new DisconnectedKeyboardInteractiveUserInfo(Password);
                else
                    throw new InvalidDataException("Cannot combine a predefined 'UserInfo' object with a predefined 'Password' value.");
            }

            m_session.setUserInfo(m_userInfo);

            //determine how strict to be on host key issues.
            Hashtable config = new Hashtable();
            switch (m_checkType)
            {
                case HostKeyCheckType.AskUser:
                    config.Add("StrictHostKeyChecking", "ask");
                    break;
                case HostKeyCheckType.ForceMatch:
                    config.Add("StrictHostKeyChecking", "yes");
                    break;
                case HostKeyCheckType.NoCheck:
                    config.Add("StrictHostKeyChecking", "no");
                    break;
                default:
                    throw new InvalidDataException("Unknown value provided for 'm_checkType' property");
            }
            m_session.setConfig(config);

            if (m_hostKeyFileName != null)
                m_jsch.getHostKeyRepository().setKnownHosts(m_hostKeyFileName);

            m_session.connect();
        }