title: Stream interface to a file on SFTP server in C# SSH.NET
body: <p>I am connecting to an SFTP server using SSH.NET and trying to read an image into a stream for displaying it in my web page.</p>
  <pre><code>SftpClient client = connectToServer(IP,user,pwd); 
  string remotePath = client.WorkingDirectory.ToString() + dto.Directory + &quot;/&quot;; 
  FileStream fs = new FileStream(remotePath + dto.FileName,FileMode.Open); 
  Stream strm = fs;
  </code></pre>
  <p>The above code throws an invalid characters exception. I am not sure if the reason for it is because of the filename on the server i.e. all these files are stored with <code>*</code> delimiter i.e. <code>Text1*Text2*Text3.00.png</code>.</p>
  <p>If it is, is there any other way to read the stream?</p>
  <p>I have also tried to read from <code>HttpResponse.OutputStream</code> but that throws a read/seek invalid exception.</p>
  <pre><code>HttpResponse response = HttpContext.Current.Response;
  Stream strm = response.OutputStream;
  </code></pre>
  <p>Are there any other ways to read such image files?
  <a href="https://i.stack.imgur.com/aPs7d.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/aPs7d.png" alt="enter image description here" /></a></p>
  <hr />
  <p>This is the working code code for the same functionality using <code>FtpWebRequest</code>.</p>
  <pre><code>var request = (FtpWebRequest)WebRequest.Create(serverUri);
  request.UsePassive = true;
  request.UseBinary = true;
  request.Credentials =// 
  request.Method = WebRequestMethods.Ftp.DownloadFile;
  response = (FtpWebResponse)await request.GetResponseAsync();
  Stream responseStream = response.GetResponseStream();
  </code></pre>
  <p>I am changing it to SFTP using SSH.NET.</p>
  <p>Is there a way to get the same output as <code>GetResponseStream()</code> with SSH.NET?</p>