Upload data from memory to SFTP server using SSH.NET

僤鯓⒐⒋嵵緔 提交于 2019-11-28 02:10:15

问题


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

ReportExecutionService rsExec = new ReportExecutionService();

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

回答1:


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


来源:https://stackoverflow.com/questions/45945512/upload-data-from-memory-to-sftp-server-using-ssh-net

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!