Write() public method

Writes a sequence of bytes to the current stream and advances the current position within this stream by the number of bytes written.
The sum of and is greater than the buffer length. is null. or is negative. An I/O error occurs. The stream does not support writing. Methods were called after the stream was closed.
public Write ( byte buffer, int offset, int count ) : void
buffer byte An array of bytes. This method copies bytes from to the current stream.
offset int The zero-based byte offset in at which to begin copying bytes to the current stream.
count int The number of bytes to be written to the current stream.
return void
Example #1
0
        public void ExeSSH(Object s)
        {
            using (var conninfo = new PasswordConnectionInfo(ip, log, pass))
            {
                //  try

                Renci.SshNet.SshClient client = new Renci.SshNet.SshClient(conninfo);

                //  conninfo.Timeout = TimeSpan.FromSeconds(50);
                try
                {
                    client.Connect();
                }
                catch (Exception ex)
                {
                }
                try
                {
                    Renci.SshNet.ShellStream stream = client.CreateShellStream("ssh", 180, 324, 1800, 3600, 8000);
                    foreach (string command in list)
                    {
                        stream.Write(command + "\n");
                        System.Threading.Thread.Sleep(5000);
                        string temp_string = stream.Read();
                        //    File.WriteAllText(path, temp_string, Encoding.UTF8);
                        File.WriteAllText("C:/" + ip + ".txt", temp_string, Encoding.UTF8);
                        System.Threading.Thread.Sleep(5000);
                    }
                    client.Disconnect();
                }
                catch (Exception ex)
                {
                }
            }
        }
Example #2
0
 public void ExSSH(string ip, string log, string pass, List <String> list)
 {
     //     foreach (string ipadd in ip)
     //     {
     using (var conninfo = new PasswordConnectionInfo(ip, log, pass))
     {
         Renci.SshNet.SshClient client = new Renci.SshNet.SshClient(conninfo);
         client.Connect();
         Renci.SshNet.ShellStream stream = client.CreateShellStream("ssh", 180, 324, 1800, 3600, 8000);
         foreach (string command in list)
         {
             // var command = "show config modified";
             stream.Write(command + "\n");
             System.Threading.Thread.Sleep(10000);
             string temp_string = stream.Read();
             //  Console.Write(temp_string);
             File.WriteAllText("C:/" + ip + " thread n- " + System.Threading.Thread.CurrentThread.ManagedThreadId + ".txt", temp_string, Encoding.UTF8);
             //     System.Threading.Thread.Sleep(5000);
         }
         client.Disconnect();
         //   }
     }
 }