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

时间:2017-08-29 17:55:27

标签: c# .net sftp 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();

1 个答案:

答案 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");
相关问题