简体   繁体   English

如何通过Sharp SSH库传输内存流对象?

[英]How to transfer memory stream object through Sharp SSH library?

I am creating a memory stream on run time 我在运行时创建内存流

        var stream = new MemoryStream();
        var writer = new StreamWriter(stream); 
        writer.WriteLine("There could by any text over here....");
        writer.Flush();
        stream.Position = 0;

Now i want to transfer this memory stream via SSH library to a remote SFTP server and want to save it on that SFTP server. 现在,我想通过SSH库将此内存流传输到远程SFTP服务器,并将其保存在该SFTP服务器上。

I have tried following code but its not working 我试过下面的代码,但是不起作用

     using (var scp = new ScpClient("HostName", "test", "test"))
        {
            scp.Connect();
            scp.Upload(stream, "/Files/Test/temp.txt");
            scp.Disconnect();
        }

it get stuck forever on following line without any error 它永远卡在下一行,没有任何错误

scp.Upload(stream, "/Files/Test/temp.txt");

Can any one please help? 有人可以帮忙吗?

Use SftpClient.UploadFile instead of ScpClient.Upload . 使用SftpClient.UploadFile而不是ScpClient.Upload

If that doesn't help, make sure your firewall is set up properly. 如果这样做没有帮助,请确保正确设置了防火墙。 It's very helpful to use a tool such as WireShark to monitor the communication in case there's some weird error (it also enables you to easily see authentication errors etc.). 使用WireShark之​​类的工具来监视通信,以防万一出现一些奇怪的错误(它也使您能够轻松地查看身份验证错误等)非常有用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM