当前位置: 首页>>代码示例>>C#>>正文


C# SshClient.CreateShellStream方法代码示例

本文整理汇总了C#中Renci.SshNet.SshClient.CreateShellStream方法的典型用法代码示例。如果您正苦于以下问题:C# SshClient.CreateShellStream方法的具体用法?C# SshClient.CreateShellStream怎么用?C# SshClient.CreateShellStream使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Renci.SshNet.SshClient的用法示例。


在下文中一共展示了SshClient.CreateShellStream方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: connect

        private static void connect(string hostName, string userName, string password)
        {
            if (client != null && client.IsConnected)
                return;

            var connectionInfo = new KeyboardInteractiveConnectionInfo(hostName, userName);
            connectionInfo.AuthenticationPrompt += delegate(object sender, AuthenticationPromptEventArgs e)
            {
                foreach (var prompt in e.Prompts)
                    prompt.Response = password;
            };

            client = new SshClient(connectionInfo);
            client.Connect();

            sshStream = client.CreateShellStream("", 80, 40, 80, 40, 1024);

            shellCommand("python", null);

            using (var sr = new System.IO.StreamReader("queryJoints.py"))
            {
                String line;
                while ((line = sr.ReadLine()) != null)
                    pythonCommand(line);
            }
        }
开发者ID:fakusb,项目名称:FiVES-Nao-Visualisation,代码行数:26,代码来源:Program.cs

示例2: Main

        static void Main(string[] args)
        {
            Console.WriteLine("fd");

            try
            {
                ssh = new SshClient("10.141.3.110", "root", "ismail");
                ssh.Connect();
                 //status = true;
                 //timer_enable();
            }
            //catch (Exception ex)
            // {
            //    Console.Write(ex.Message);
            //}

            catch { }

               if (true)
            try
            {
                stream = ssh.CreateShellStream("xterm", 80, 50, 1024, 1024, 1024);
                Thread.Sleep(100);
                stream.WriteLine("telnet localhost 6571");
                Thread.Sleep(100);
            }
            catch (Exception)
            {
                Console.WriteLine("hata");
            }

            Console.ReadKey();
        }
开发者ID:dagenes,项目名称:GitHubVS2013,代码行数:33,代码来源:Program.cs

示例3: Connect

        public void Connect(ConnectionSettings settings, int terminalCols, int terminalRows)
        {
            Settings = settings;
            if (dataThread != null)
                throw new InvalidOperationException("Already connecting to a server.");
            dataThread = new Thread(() =>
            {
            #if USE_LIBSSHNET
                var connection = new LibSshNetConnection(serverAddress, username, (authentications.First() as PasswordAuthentication).Password);
                stream = connection.GetStream();
            #else
                try
                {
                    var authentications = new List<AuthenticationMethod>();
                    if (!string.IsNullOrEmpty(settings.KeyFilePath))
                    {
                        var privateKeyFile = new PrivateKeyFile(settings.KeyFilePath, settings.KeyFilePassphrase);
                        authentications.Add(new PrivateKeyAuthenticationMethod(settings.Username, privateKeyFile));
                    }
                    authentications.Add(new PasswordAuthenticationMethod(settings.Username, settings.Password));
                    ConnectionInfo connectionInfo = new ConnectionInfo(settings.ServerAddress, settings.ServerPort, settings.Username, authentications.ToArray());

                    Client = new SshClient(connectionInfo);
                    Client.Connect();

                    Client.KeepAliveInterval = TimeSpan.FromSeconds(20);

                    Stream = Client.CreateShellStream("xterm-256color", (uint) terminalCols, (uint) terminalRows, 0, 0, 1000);

                    if (Connected != null)
                        Connected(this, EventArgs.Empty);
                }
                catch (Exception ex)
                {
                    ConnectionFailedEventArgs args = null;
                    if (ex is Renci.SshNet.Common.SshPassPhraseNullOrEmptyException ||
                        ex is InvalidOperationException)
                        args = new ConnectionFailedEventArgs(ConnectionError.PassphraseIncorrect, ex.Message);
                    else if (ex is SocketException)
                        args = new ConnectionFailedEventArgs(ConnectionError.NetError, ex.Message);
                    else if (ex is Renci.SshNet.Common.SshAuthenticationException)
                        args = new ConnectionFailedEventArgs(ConnectionError.AuthenticationError, ex.Message);
                    else
                        throw;

                    if (Failed != null)
                        Failed(this, args);
                }
            #endif
            });
            dataThread.Name = "Data Thread";
            dataThread.IsBackground = true;
            dataThread.Start();
        }
开发者ID:npcook,项目名称:terminal,代码行数:54,代码来源:Connection.cs

示例4: SSH

        private static MyAsyncInfo info;                // unique class containing information obtained from an asynchronous read

        // constructor that initializes the client object and creates a connection to the remote terminal
        public SSH(string IP, string user, string pass)
        {
            // initilizes client object containing server information
            client = new SshClient(IP, user, pass);

            // connects to the server
            client.Connect();

            // creates a stream to communicate with the remote terminal
            stream = client.CreateShellStream(@"xterm", 80, 24, 800, 600, 2048);
        }
开发者ID:jstewart1172,项目名称:MalwareVis_SSH,代码行数:14,代码来源:SSH.cs

示例5: flash_px4

        public static void flash_px4(string firmware_file)
        {
            if (is_solo_alive)
            {
                using (SshClient client = new SshClient("10.1.1.10", 22, "root", "TjSDBkAu"))
                {
                    client.KeepAliveInterval = TimeSpan.FromSeconds(5);
                    client.Connect();

                    if (!client.IsConnected)
                        throw new Exception("Failed to connect ssh");

                    var retcode = client.RunCommand("rm -rf /firmware/loaded");
                    
                    using (ScpClient scpClient = new ScpClient(client.ConnectionInfo))
                    {
                        scpClient.Connect();

                        if (!scpClient.IsConnected)
                            throw new Exception("Failed to connect scp");

                        scpClient.Upload(new FileInfo(firmware_file), "/firmware/" + Path.GetFileName(firmware_file));
                    }

                    var st = client.CreateShellStream("bash", 80, 24, 800, 600, 1024*8);

                    // wait for bash prompt
                    while (!st.DataAvailable)
                        System.Threading.Thread.Sleep(200);

                    st.WriteLine("loadPixhawk.py; exit;");
                    st.Flush();

                    StringBuilder output = new StringBuilder();

                    while (client.IsConnected)
                    {
                        var line = st.Read();
                        Console.Write(line);
                        output.Append(line);
                        System.Threading.Thread.Sleep(100);

                        if (output.ToString().Contains("logout"))
                            break;
                    }
                }
            }
            else
            {
                throw new Exception("Solo is not responding to pings");
            }
        }
开发者ID:ArduPilot,项目名称:MissionPlanner,代码行数:52,代码来源:Solo.cs

示例6: _main

        static void _main()
        {
            BlackCore.basic.cParams args = bcore.app.args;

               client = new System.Net.Sockets.TcpClient();

               int wavInDevices = WaveIn.DeviceCount;
               int selWav = 0;
               for (int wavDevice = 0; wavDevice < wavInDevices; wavDevice++)
               {
               WaveInCapabilities deviceInfo = WaveIn.GetCapabilities(wavDevice);
               Console.WriteLine("Device {0}: {1}, {2} channels", wavDevice, deviceInfo.ProductName, deviceInfo.Channels);
               }

               Console.Write("Select device: ");
               selWav = int.Parse(Console.ReadLine());
               Console.WriteLine("Selected device is " + selWav.ToString());

               sshClient = new SshClient(args["host"], args["user"], args["pass"]);
               sshClient.Connect();

               if (sshClient.IsConnected)
               {

               shell = sshClient.CreateShellStream("xterm", 50, 50, 640, 480, 17640);
               Console.WriteLine("Open listening socket...");
               shell.WriteLine("nc -l " + args["port"] + "|pacat --playback");
               System.Threading.Thread.Sleep(2000);

               Console.WriteLine("Try to connect...");
               client.Connect(args["host"], int.Parse(args["port"]));
               if (!client.Connected) return;
               upStream = client.GetStream();

               //====================

               WaveInEvent wavInStream = new WaveInEvent();
               wavInStream.DataAvailable += new EventHandler<WaveInEventArgs>(wavInStream_DataAvailable);
               wavInStream.DeviceNumber = selWav;
               wavInStream.WaveFormat = new WaveFormat(44100, 16, 2);
               wavInStream.StartRecording();
               Console.WriteLine("Working.....");

               Console.ReadKey();
               sshClient.Disconnect();
               client.Close();
               wavInStream.StopRecording();
               wavInStream.Dispose();
               wavInStream = null;
               }
        }
开发者ID:hapylestat,项目名称:StreamAudio,代码行数:51,代码来源:Program.cs

示例7: PythonConnection

        public PythonConnection(string hostName, string userName, string password)
        {
            var connectionInfo = new KeyboardInteractiveConnectionInfo(hostName, userName);
            connectionInfo.AuthenticationPrompt += delegate(object sender, AuthenticationPromptEventArgs e)
            {
                foreach (var prompt in e.Prompts)
                    prompt.Response = password;
            };

            client = new SshClient(connectionInfo);

            client.Connect();

            sshStream = client.CreateShellStream("", 80, 40, 80, 40, 1024);

            shellCommand("python", null);
        }
开发者ID:fakusb,项目名称:FiVES-Nao-Visualisation,代码行数:17,代码来源:PythonConnection.cs

示例8: BasicRemoteOperations

        internal BasicRemoteOperations(IDeploymentContext context, IHost host)
        {
            Context = context;

            Sftp = new SftpClient(host.Hostname, host.Username, host.Password)
                {
                    OperationTimeout = TimeSpan.FromMinutes(2),
                    ConnectionInfo = {Timeout = TimeSpan.FromMinutes(2)},
                    BufferSize = 1024*16
                };
            Sftp.Connect();

            Shell = new SshClient(host.Hostname, host.Username, host.Password);
            Shell.Connect();
            ShellStream = Shell.CreateShellStream(
                String.Format("{0}@{1}", host.Username, host.Hostname), 0, 0, 0, 0, 1024);
        }
开发者ID:nemec,项目名称:Blossom,代码行数:17,代码来源:BasicRemoteOperations.cs

示例9: MySshStream

        public MySshStream(string host, string username, string password)
        {
            SshClient ssh = new SshClient(GenerateConnectionInfo(host, username, password));
            ssh.Connect();
            if (!ssh.IsConnected)
                throw new Exception("Can't connect to host: " + ssh.ConnectionInfo.Host);

            var x = new Dictionary<Renci.SshNet.Common.TerminalModes, uint>();
            //x.Add(Renci.SshNet.Common.TerminalModes.VERASE, 0);
            stream = ssh.CreateShellStream("dumb", 80, 24, 800, 600, 1024,x);
            stream.DataReceived += stream_DataReceived;
            reader = new StreamReader(stream);
            writer = new StreamWriter(stream);
            writer.AutoFlush = true;

            outputWriter = new StreamWriter(memoryStream);
            shellOutpu = new StreamReader(memoryStream);
        }
开发者ID:emote-project,项目名称:Scenario1,代码行数:18,代码来源:MySshStream.cs

示例10: ReadBack

        public void ReadBack()
        {
            var info = util.GetUsernameAndPassword();

            var sclist = new CredentialSet(info.Item1);
            var passwordInfo = sclist.Load().Where(c => c.Username == info.Item2).FirstOrDefault();
            if (passwordInfo == null)
            {
                throw new ArgumentException(string.Format("Please create a generic windows credential with '{0}' as the target address, '{1}' as the username, and the password for remote SSH access to that machine.", info.Item1, info.Item2));
            }

            // Create the connection, but do it lazy so we don't do anything if we aren't used.
            var host = info.Item1;
            var username = info.Item2;
            var password = passwordInfo.Password;

            // Do the work.
            var con = new SshClient(host, username, password);
            con.Connect();

            var s = con.CreateShellStream("Commands", 240, 200, 132, 80, 1024);

            var reader = new StreamReader(s);
            var writer = new StreamWriter(s);
            writer.AutoFlush = true;

            // Do the read command
            writer.WriteLine("read -p \"hi there: \" bogus");
            Thread.Sleep(200);
            writer.Write("Life Is Great\n");
            Thread.Sleep(200);
            writer.WriteLine("set | grep bogus");

            Thread.Sleep(200);

            string l = "";
            while ((l = reader.ReadLine()) != null)
            {
                Console.WriteLine(l);
            }

            Assert.Inconclusive();
        }
开发者ID:LHCAtlas,项目名称:AtlasSSH,代码行数:43,代码来源:RawInteractions.cs

示例11: Connect

 public bool Connect()
 {
     System.Diagnostics.Debug.WriteLineIf(DEBUG, "ssh: connecting ....");
     try
     {
         ConnectionInfo info = new PasswordConnectionInfo(_host,_port, _user, _pw);
         _client = new SshClient(info);
         _client.ErrorOccurred += SSHError;
         _client.Connect();
         _stream = _client.CreateShellStream("xterm", 80, 24, 800, 600, 1024);
         System.Diagnostics.Debug.WriteLineIf(DEBUG, "ssh: connected");
         return true;
     }
     catch (System.Exception e)
     {
         System.Diagnostics.Debug.WriteLineIf(DEBUG, "ssh: error while connecting:");
         System.Diagnostics.Debug.WriteLine(e.Message);
         System.Diagnostics.Debug.WriteLine(e.InnerException);
         return false;
     }
 }
开发者ID:nolith,项目名称:RSSSHClient,代码行数:21,代码来源:RSSSHConnector.cs

示例12: SSHForm_Load

        private void SSHForm_Load(object sender, EventArgs e)
        {
            client = new SshClient(server, port, user,pwd);
            client.Connect();

            string reply = string.Empty;
            shellStream = client.CreateShellStream("dumb", 80, 24, 800, 600, 1024);
            reply = shellStream.Expect(new Regex(@":.*>#"), new TimeSpan(0, 0, 3));

            shellStream.DataReceived += ShellStream_DataReceived;

            richTextBox1.Text = "server connected\n";
            richTextBox1.SelectionStart = richTextBox1.Text.Length;
            richTextBox1.ScrollToCaret();
        }
开发者ID:dragon753,项目名称:Deployer,代码行数:15,代码来源:SSHForm.cs

示例13: baglan

//
//
//        
//
        //int connect; 
        //connect degiskeninini simdilik kullanmiyoruz.. 

        //baglanma fonksiyonu tanimlamasi 

       

        public void baglan()
        {

            ssh = new SshClient("10.141.3.110", "root", "ismail");

            try
            {

                ssh = new SshClient("10.141.3.110", "root", "ismail");
                ssh.Connect();
                status = true;
                //connect = 1;
            }
            catch
            {
                status = false;
                tl.LogMessage("hata", "baglanti hatasi, tekrar deneyin.. [uc kapak getirene bardak hediye..]");
                //connect = 0;
            
            }

            if(status==true)
            {
                try
                {

                    stream = ssh.CreateShellStream("xterm", 80, 50, 1024, 1024, 1024);
                    Thread.Sleep(100);
                    stream.WriteLine("telnet localhost 6571");
                    Thread.Sleep(100);
                    kontrol();

                }

                catch
                { 
                }



            }

        }
开发者ID:dagenes,项目名称:ata50kubbedriver,代码行数:54,代码来源:Driver.cs

示例14: ExecuteEnableModeCommands

 //выполнение команд в привилегированном режиме
 private void ExecuteEnableModeCommands(SshClient sshClient, List<string> commands)
 {
     using (ShellStream client = sshClient.CreateShellStream("terminal", 80, 24, 800, 600, 1024))
     {
         SendCommandLF("enable", client);//переходим в привилегированный режим
         SendCommand(_host.enablePassword, client);//подтверждаем наши права
         foreach (string command in commands)
         {
             _listResult.Add(SendCommand(command, client));
         }
         //Console.WriteLine("4 [" + SendCommand("terminal pager 0", client) + "]");
         //Console.WriteLine("3 [" + SendCommand("show version", client) + "]");
         //Console.WriteLine("5 [" + SendCommand("show run", client) + "]");
         //Console.WriteLine("1 [" + SendCommandW("show interface ?", client) + "]");
     }
 }
开发者ID:DaurenAmanbayev,项目名称:RemoteWork,代码行数:17,代码来源:SshExpect.cs

示例15: SSHConnection

        public SSHConnection(string host, string username)
        {
            this._host = host;
            this._username = username;

            _ssh = new SshClient(_host, _username, Passwords.FetchPassword(_host, _username));
            _ssh.Connect();
            _stream = _ssh.CreateShellStream("commands", 240, 200, 132, 80, 240 * 200);

            // Next job, wait until we get a command prompt

            _stream.WriteLine("# this is a test");
            DumpTillFind(_stream, "# this is a test");
            _prompt = _stream.ReadLine();
        }
开发者ID:gordonwatts,项目名称:SSHExperiments,代码行数:15,代码来源:SSHConnection.cs


注:本文中的Renci.SshNet.SshClient.CreateShellStream方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。