title: Using SshNet to Retrieve Folder List from Remote Server (SSH Interactive Client)
body: <p>I am trying to create an interactive SSH client session in C#. I am using the Renci.SshNet library to accomplish this. To get a proof of concept, I am only interested in connecting to the server, running the "ls" command, and retrieving the list of folders in the current directory.</p>
  
  <p>I have been able to do this, however, I am getting (I believe) server domain's in my output as well as the file names. I have provided a picture at the bottom to show exactly what I am getting. I am not sure how to parse this....or am I even doing this the correct way? I have provided my code, a picture of the output, and what I wish the output to be.</p>
  
  <pre><code>// using....
  using Renci.SshNet;
  
  class Program
  {
      private const String NEWLINE = "\n";
      private bool connected = false;
      static void Main(string[] args)
      {
          Console.Write("Enter hostname: ");
          String hostname = Console.ReadLine();
          Console.Write("Enter username: ");
          String username = Console.ReadLine();
          Console.Write("Enter password: ");
          String password = Console.ReadLine();
  
  
          PasswordAuthenticationMethod pw = new PasswordAuthenticationMethod(username, password);
          ConnectionInfo ci = new ConnectionInfo(hostname, username, pw);
          SshClient ssh = new SshClient(ci);
  
          Console.Write("-Connecting...\n");
          ssh.Connect();
  
          IDictionary&lt;Renci.SshNet.Common.TerminalModes, uint&gt; termkvp = new Dictionary&lt;Renci.SshNet.Common.TerminalModes, uint&gt;();
          termkvp.Add(Renci.SshNet.Common.TerminalModes.ECHO, 53);
          ShellStream shellStream = ssh.CreateShellStream("xterm", 80, 24, 800, 600, 1024, termkvp);
  
          String line = null;
          String s = null;
  
          TimeSpan timeout = new TimeSpan(0, 0, 1);
          while ((s = shellStream.ReadLine(timeout)) != null)
          {
              Console.WriteLine(s);
          }
          shellStream.Flush();
  
          while((line = Console.ReadLine()) != "exit")
          {
              shellStream.Write(line);
              shellStream.Write(NEWLINE);
  
              while ((s = shellStream.ReadLine(timeout)) != null)
              {
                  Console.WriteLine(s);
              }
              shellStream.Flush();
          }
          Console.Write("Press any key to continue...");
          Console.ReadLine();
      }
  }
  </code></pre>
  
  <p>Output:</p>
  
  <p>(I have highlighted the portions that I am interested in getting)</p>
  
  <p><img src="https://i.stack.imgur.com/NgmLU.png" alt="enter image description here"></p>
  
  <p>Expected Output:</p>
  
  <pre><code>- Connecting...
  Last login: Thu Apr 30 10:28:12 2015 from ...
  ls     (user input)
      2015-03-18_0
      First_HFSS_Test
      First_Test
      ...
  </code></pre>
  
  <p><strong><em>EDIT</em></strong></p>
  
  <p>When I use "dir" instead of "ls" I get the list of directory without the other information. I believe that the "ls" gives me the list with color information. Perhaps the information outside of the directory list is color data that has been translated???</p>