I am hoping to write PDF's directly to SFTP site. The PDF's are generated from ReportExecutionService.Render (SSRS).
ReportExecutionService rsExec = new ReportExecutionService();
I have been able to write the files locally using FileStream. I am generating millions of files, so I am hoping to write them directly on SFTP using SSH.NET. What is the syntax for taking the rsExec.Render result and writing to SFTP using SSH.NET?
string deviceInfo = null;
string extension;
string encoding;
string mimeType;
ConsoleApp2.ReportExecution2005.Warning[] warnings = null;
string[] streamIDs = null;
string format = "PDF";
Byte[] results =
rsExec.Render(
format, deviceInfo, out extension, out mimeType, out encoding,
out warnings, out streamIDs);
FileStream stream = File.OpenWrite("C:\\test.pdf");
stream.Write(results, 0, results.Length);
stream.Close();
Wrap the byte array to a MemoryStream and use SftpClient.UploadFile to upload it
var client = new SftpClient(host, port, username, password);
client.Connect();
var stream = new MemoryStream(results);
client.UploadFile(stream, "/remote/path/my.pdf");
Though most data-manipulation libraries can use the Stream API directly. That would be more efficient to use, instead of copying the data over via byte[] array.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With