我希望将PDF直接写入SFTP网站。 PDF是从ReportExecutionService.Render
(SSRS)生成的。
ReportExecutionService rsExec = new ReportExecutionService();
我已经能够使用FileStream
在本地编写文件。我正在生成数百万个文件,所以我希望使用SSH.NET直接在SFTP上编写它们。使用SSH.NET获取rsExec.Render
结果并写入SFTP的语法是什么?
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();
答案 0 :(得分:2)
将byte
数组复制到MemoryStream
并使用SftpClient.UploadFile
上传
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");