ssh connection in C# windows 10 app

2019-02-19 09:55发布

问题:

I have been looking far and wide for 2 days for something that can help me with this. I need a way to connect to an ssh server from a Windows 10 Universal app. This means that normal ssh libraries wont work, and tcpclient doesn't exist. How can I do this? Thanks in advance.

回答1:

I also failed to find SSH library which could be directly used in UWP App. There are several possible ways, hope it will help.

Method#1: Port the SSH.NET to UWP

Challenges - .NET for UWP did not provide the Socket Level Network API. It is impossible for a pure .NET library implement the SSH connection. It needs to leverage the Microsoft API in Windows Runtime Library.

Mthod#2: Wrap an existing C/C++ SSH library like libssh into a Windows Runtime Component

Challenges – the C/C++ library cannot use the API that are not allowed in UWP platform, else you cannot submit your app to the App Store.



回答2:

According to this GitHub Issue, SSH.NET supports UAP 10/UWP as of SSH.NET 2016.0.0-beta1.

You can download it here: https://www.nuget.org/packages/SSH.NET

Then use it doing something like:

using (var client = new SshClient("hostnameOrIp", "username", "password"))
{
    client.Connect();
    client.RunCommand("...");
    client.Disconnect();
}