title: C# Connect via SSH and changing the file content
body: <p>I am a C # amateur I am not a professional developer and would like to ask my colleagues for help, I would like to make a C # program that connects to an SSH server. Then, depending on the selected value in combobox, the program downloads the appropriate string and I would like to send it to the ssh server to the specified path path and save the value from the string to the file;)</p>
  <p>I tried to rewrite the code but something did not work out and I stopped in my place ;( Can anyone help me. Thanks in advance for your help.</p>
  <p>this is my code</p>
  <pre class="lang-csharp prettyprint-override"><code>using System;
  using System.Collections.Generic;
  using System.ComponentModel;
  using System.Data;
  using System.Drawing;
  using System.Linq;
  using System.Text;
  using System.Threading.Tasks;
  using System.Windows.Forms;
  using System.Threading;
  using Renci.SshNet;
  
  namespace FileGenerator
  {
  
      public partial class Form1 : Form
      {
          public Form1()
          {
              InitializeComponent();
          }
  
  
          private void btnConnect_Click(object sender, EventArgs e)
          {
              SshClient sshClient = new SshClient(&quot;192.168.1.22&quot;, 22, &quot;root&quot;, &quot;pass&quot;);
  
              sshClient.ConnectionInfo.Timeout = TimeSpan.FromSeconds(120);
              sshClient.Connect();
  
              ShellStream shellStreamSSH = sshClient.CreateShellStream(&quot;vt-100&quot;, 80, 60, 800, 600, 65536);
  
              Thread thread = new Thread(() =&gt; recvSSHData(shellStreamSSH));
  
              thread.Start();
  
              //I don't know how to get the information if it is connected correctly and change e.g. btnConnect label to Connected.
  
          }
  
  
          public static void recvSSHData(ShellStream shellStreamSSH)
          {
  
              while (true)
              {
                  try
                  {
                      if (shellStreamSSH != null &amp;&amp; shellStreamSSH.DataAvailable)
                      {
                          string strData = shellStreamSSH.Read();
  
                      }
  
  
                  }
                  catch
                  {
  
                  }
  
                  System.Threading.Thread.Sleep(200);
              }
  
  
          }
  
  
          string data1 = &quot;data1&quot;;
          string data2 = &quot;data2&quot;;
          string data3 = &quot;data3&quot;;
          string check;
          string path = &quot;/home/test01/desktop&quot;;
          string filename = &quot;test.txt&quot;;
          private void btnSend_Click(object sender, EventArgs e)
          {
  
  
              if (cmbData.SelectedIndex == 0)
              {
                  check = data1;
                  MessageBox.Show(check);
              }
              else if (cmbData.SelectedIndex == 1)
              {
                  check = data2;
                  MessageBox.Show(check);
              }
              else if (cmbData.SelectedIndex == 2)
              {
                  check = data3;
                  MessageBox.Show(check);
              }
              else
              {
                  MessageBox.Show(&quot;Choose a value&quot;);
  
              }
  
          //And now there should be an instruction that sends a string check to the server to path to file replacing its contents
  
          }
  
  
      }
  }
  </code></pre>