Beispiel #1
0
        /// <summary>
        /// Constructs a new SSH stream.
        /// </summary>
        /// <param name="host">The hostname or IP address of the remote SSH machine</param>
        /// <param name="username">The name of the user connecting to the remote machine</param>
        /// <param name="password">The password of the user connecting to the remote machine</param>
        public SshStream(string host, string username, string password)
        {
            this.m_host = host;
            SshClient jsch = new SshClient();

            m_session = jsch.getSession(username, host, 22);
            m_session.setPassword(password);

            Hashtable config = new Hashtable();

            config.Add("StrictHostKeyChecking", "no");
            m_session.setConfig(config);

            m_session.connect();
            m_channel = (ChannelShell)m_session.openChannel("shell");

            m_in  = m_channel.getInputStream();
            m_out = m_channel.getOutputStream();

            m_channel.connect();
            m_channel.setPtySize(80, 132, 1024, 768);

            Prompt = "\n";
            m_escapeCharPattern = "\\[[0-9;?]*[^0-9;]";
        }
Beispiel #2
0
        public SshHelper(string host, string username, string password)
        {
            this.host = host;
            JSch    jsch    = new JSch();
            Session session = jsch.getSession(username, host, 22);

            session.setPassword(password);

            Hashtable config = new Hashtable();

            config.Add("StrictHostKeyChecking", "no");
            session.setConfig(config);

            session.connect();

            channel = (ChannelShell)session.openChannel("shell");

            writer_po = new PipedOutputStream();
            PipedInputStream writer_pi = new PipedInputStream(writer_po);

            PipedInputStream  reader_pi = new PipedInputStream();
            PipedOutputStream reader_po = new PipedOutputStream(reader_pi);

            reader = new StreamReader(reader_pi, Encoding.UTF8);


            channel.setInputStream(writer_pi);
            channel.setOutputStream(reader_po);

            channel.connect();
            channel.setPtySize(132, 132, 1024, 768);
        }
Beispiel #3
0
        /// <summary>
        /// Constructs a new SSH stream.
        /// </summary>
        /// <param name="host">The hostname or IP address of the remote SSH machine</param>
        /// <param name="username">The name of the user connecting to the remote machine</param>
        /// <param name="password">The password of the user connecting to the remote machine</param>
        /// <param name="privateKeyPath">privateKeyPath</param>
        public SshStream(string host, string username, string password, string privateKeyPath)
        {
            this.m_host = host;
            JSch jsch = new JSch();

            m_session = jsch.getSession(username, host, 22);
            if (string.IsNullOrEmpty(password))
            {
                jsch.addIdentity(privateKeyPath);
            }
            else
            {
                m_session.setPassword(password);
            }

            Hashtable config = new Hashtable();

            config.Add("StrictHostKeyChecking", "no");
            m_session.setConfig(config);

            m_session.connect();
            m_channel = (ChannelShell)m_session.openChannel("shell");

            m_in  = m_channel.getInputStream();
            m_out = m_channel.getOutputStream();

            m_channel.connect();
            m_channel.setPtySize(80, 132, 1024, 768);

            Prompt = "\n";
            m_escapeCharPattern = "\\[[0-9;?]*[^0-9;]";
        }
Beispiel #4
0
        private void OpenStream(string username, string password, bool retry)
        {
            try
            {
                JSch jsch = new JSch();
                m_session = jsch.getSession(username, this.m_host, 22);
                //m_session.setPassword( password );
                m_session.setUserInfo(new KeyboardInteractiveUserInfo(password));

                Hashtable config = new Hashtable();
                config.Add("StrictHostKeyChecking", "no");
                m_session.setConfig(config);

                m_session.connect();
                m_channel = (ChannelShell)m_session.openChannel("shell");

                m_in  = m_channel.getInputStream();
                m_out = m_channel.getOutputStream();

                m_channel.connect();
                m_channel.setPtySize(80, 132, 1024, 768);

                if (m_in is PipedInputStream)
                {
                    ((PipedInputStream)m_in).UpdateThreadsFromChannel(m_channel);
                }

                Prompt = "\n";
                m_escapeCharPattern = "\\[[0-9;?]*[^0-9;]";
            }
            catch (Exception e)
            {
                                #if DEBUG
                Console.WriteLine("Error opening SshStream to target: " + m_host + (retry ? ", re-attempting connection" : ""));
                                #endif

                this.Close();
                if (retry)
                {
                    OpenStream(username, password, false);
                }
                else
                {
                    throw e;
                }
            }
        }