0

如何将文件从内存流上传到 SFTP 服务器。本地路径不可用,因为我正在从 azure blob 上传文件。因为我得到了 .NET 不支持 SFTP 协议的信息,因此尝试了 3rd 方 dll,例如“SharpSSH”、“Routrek.granados”和“WinSCP”。但是没有一个适合我的场景。即 put 方法不支持 bit[] 或 stream。

任何人都可以建议我免费且适合我的情况的dll或我可以处理的方式。

提前致谢。

4

1 回答 1

1

您可以继续使用 WinSCP 之类的解决方案,但不要尝试使用 MemoryStream / byte[],只需先在本地下载文件:

var client = account.CreateCloudBlobClient();
var container = client.GetContainerReference("temp");
var blob = container.GetBlobReferenceFromServer("myblob.zip");

// This assumes you're using a Cloud Service and have a local resource called files
var dropFolder = RoleEnvironment.GetLocalResource("files").RootPath;
var filePath = Path.Combine(dropFolder, "myblob.zip");

// Download blob to a local resource first.
using (var fs = new FileStream(filePath, FileMode.Create))
{
    blob.DownloadToStream(fs);
}

var proc = new Process();
proc.StartInfo.FileName = "winscp.com";
proc.StartInfo.UseShellExecute = false;
proc.StartInfo.RedirectStandardInput = true;
proc.StartInfo.RedirectStandardOutput = true;
proc.StartInfo.CreateNoWindow = true;
proc.Start();
proc.StandardInput.WriteLine("option batch abort");
proc.StandardInput.WriteLine("option confirm off");
proc.StandardInput.WriteLine("open mysession");
proc.StandardInput.WriteLine("ls");
proc.StandardInput.WriteLine("put " + filePath);
proc.StandardInput.Close();
于 2013-02-13T07:56:48.797 回答