使用SSH.NET将数据从内存上传到SFTP服务器
问题描述:
我希望将PDF直接写入SFTP站点。 PDF是从ReportExecutionService.Render
(SSRS)生成的。使用SSH.NET将数据从内存上传到SFTP服务器
ReportExecutionService rsExec = new ReportExecutionService();
我已经能够在本地写文件使用FileStream
。我生成了数百万个文件,所以我希望能够使用SSH.NET直接在SFTP上编写它们。采用rsExec.Render
结果并使用SSH.NET写入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();
答
复制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");