0

I'm trying to download a file from SFTP using the library SSH.NET, however I can not save the file in a folder, I wanted to work with it in MemoryStream format, how can I do this?

Below is the code where I connect to sftp and try to get it using sftpFile.

using (SftpClient sftp = new SftpClient(url, usuario, senha))
{
    sftp.Connect();                  
    sftp.ChangeDirectory("/HOURLY"); 

    if (sftp.Exists(nomeArquivo))
    {
        var arquivoSftp = sftp.Get(nomeArquivo);
    }

    sftp.Disconnect();
}

Thanks.

Guilherme Martin
  • 837
  • 1
  • 11
  • 22
  • Reopen vote reason? I can reopen it if this duplicate isn't right, but it seems to fit what OP is asking? – ProgrammingLlama Oct 25 '19 at 14:53
  • In case I would need to download the file but using MemoryStream, I didn't want to save it to a directory. For this reason it is not duplicated. – Guilherme Martin Oct 25 '19 at 14:54
  • 2
    @Guillherme The `DownloadFile` method takes the base `Stream` object, be it `FileStream` (as in the linked question) or `MemoryStream`. Once the download method is complete, just seek to position 0 in your memory stream and you should be good to go. – ProgrammingLlama Oct 25 '19 at 14:55
  • 1
    Or use `Open` => I've added another question to the list of duplicates. – Martin Prikryl Oct 25 '19 at 14:58

0 Answers0