![](/img/trans.png)
[英]When uploading memory stream with contents created by csvhelper using SSH.NET to SFTP server, the uploaded file is empty
[英]Upload data from memory to SFTP server using SSH.NET
我希望直接将 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();
将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");
尽管大多数库可以直接使用Stream
API。 这将更有效地使用,而不是通过byte[]
数组复制数据。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.