Downloading files to memory

Top  Previous  Next

You can download a file and store it to memory by using the Sftp.Download method that takes a System.IO.Stream as it's first argument and remote path as it's second argument.

 

Example

 

[C#]

 

// create stream in memory

MemoryStream ms = new MemoryStream();

 

// download file to memory stream

sftp.Download(ms,"testdata.txt");

 

// write memory stream to console

byte[] data = ms.GetBuffer();

Console.WriteLine(System.Text.ASCIIEncoding.ASCII.GetString(data));

 

 

[VB]

 

' create stream in memory

Dim ms As MemoryStream = New MemoryStream

 

' download file to memory stream

sftp.Download(ms, "testdata.txt")

 

' write memory stream to console

Dim data As Byte() = ms.GetBuffer

Console.WriteLine(System.Text.ASCIIEncoding.ASCII.GetString(data))