0 votes
by (120 points)

I do have a requirement. Files stored in my azure storage needs to be transferred to SFTP server directly in C#. Now I am getting the stream of the blob first then writting the stream to SFTP location which is causing some memory issues.

1 Answer

0 votes
by (144k points)

To transfer an Azure blob via Rebex SFTP client to an SFTP server without the need to keep data of the whole blob in memory, try this approach:

// get blob container client
var container = new BlobContainerClient(connectionString, "...");
container.CreateIfNotExists(PublicAccessType.Blob);

// establish Rebex SFTP session
var sftp = new Sftp();
sftp.Connect(...);
sftp.Login(...)

// get block client
var blobClient = container.GetBlobClient("myfile.zip");

// transfer data from the blob to a file on an SFTP server
using (var uploadStream = sftp.GetUploadStream("myfile.zip"))
{
    blobClient.DownloadTo(uploadStream);
}
...