title: Cast SshClient to SftpClient
body: <p>I am using <a href="https://github.com/alexbikfalvi/Renci.SshNet/blob/master/SshClient.cs" rel="nofollow noreferrer">Renci.SshNet</a> to send files and execute commands securely on my ubuntu server.</p>
  
  <p>Anyways I often need to send files and also execute commands. So what I am doing now is this:</p>
  
  <pre><code>using (Renci.SshNet.SshClient client1 = new Renci.SshNet.SshClient("someDomain.com", 22, "root", new PrivateKeyFile(@"C:\Path\To\PrivateKey\id_rsa")))
  {
      // connect
      client1.Connect();
  
      // execute a command
      var c = client1.RunCommand("echo 'hello world' &gt; /root/test.txt");
  
      // create a second connection in order to download a file 
      SftpClient client_2 = new SftpClient(client1.ConnectionInfo);
      client_2.Connect();
  
      using (FileStream fs = new FileStream("output.txt", FileMode.OpenOrCreate))
               client_2.DownloadFile("/root/test.txt", fs);
  }
  </code></pre>
  
  <p><strong>My question is can I cast from SshClient to SftpClient so that I do not have to create 2 connections?</strong> It will be great if I could do something like this:</p>
  
  <pre><code> SftpClient client_2 = (SftpClient)client1;
  </code></pre>
  
  <p>Or another solution is to pass the files in base64 format. If I do something like this to download a file will it be considered as bad practice?</p>
  
  <pre><code> var fileConentInBase64 = client1.RunCommand("cat'/root/someFile' | base64");
  </code></pre>
  
  <p>Using the same terminology to upload a file I will do:</p>
  
  <pre><code> client1.RunCommand($"echo {base64ContentOfFile} | base64 -d &gt; /path/to/file")
  </code></pre>