Downloading files to memory |
You can download a file and store it to memory by using the Download method that takes a Stream as the first argument.
Example
This example gets the contents of the remote file test.txt. It is assumed the remote file already exists.
[C#]
// test.txt contents = "This is a memory stream test.\r\n"
string rFile = "test.txt";
int buffersize = Convert.ToInt32(myFtp.GetFileSize(rFile));
// create memory stream
MemoryStream bout = new MemoryStream(buffersize);
// download remote file
myFtp.Download(bout, rFile);
// get memory stream buffer
byte[] buffer = bout.GetBuffer();
[Visual Basic]
' test.txt contents = 'This is a memory stream test.\r\n'
Dim rFile As String = "test.txt"
Dim buffersize As Double = Convert.ToDouble(myFtp.GetFileSize(rFile))
' create memory stream
Dim bout As System.IO.MemoryStream = New System.IO.MemoryStream(buffersize)
' download remote file
myFtp.Download(bout, rFile)
' get memory stream buffer
Dim buffer As Byte() = bout.GetBuffer()