使用SSH.NET将数据从内存上传到SFTP服务器

问题描述:

我希望将PDF直接写到SFTP站点。 PDF是从 ReportExecutionService.Render (SSRS)生成的。

I am hoping to write PDF's directly to SFTP site. The PDF's are generated from ReportExecutionService.Render (SSRS).

ReportExecutionService rsExec = new ReportExecutionService();

我已经能够使用 FileStream $ c在本地写入文件$ c>。我正在生成数百万个文件,因此我希望使用SSH.NET将其直接写在SFTP上。取得 rsExec.Render 结果并使用SSH.NET写入SFTP的语法是什么?

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();


复制 byte 数组到 MemoryStream 并使用 SftpClient.UploadFile 上传

Copy 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();
stream.Write(results, 0, results.Length);
stream.Position = 0;
client.UploadFile(stream, "/remote/path/my.pdf");