C# 通过C的SSH连接#

C# 通过C的SSH连接#,c#,ssh,C#,Ssh,情况就是这样。我有一台Windows机器和一台Linux机器。这两台机器之间有一个共享驱动器(映射到Q:)。我试图弄清楚如何从C#在Q:drive(共享驱动器)上创建SSH会话。我正在尝试使用SharpSsh库来实现这一点 到目前为止,这就是我所知道的,但它给了我一个错误: try { ssh = new SshStream(host, username, password); Console.WriteLine("OK ({0}/{1})", ssh.Cipher, ssh.

情况就是这样。我有一台Windows机器和一台Linux机器。这两台机器之间有一个共享驱动器(映射到Q:)。我试图弄清楚如何从C#在Q:drive(共享驱动器)上创建SSH会话。我正在尝试使用SharpSsh库来实现这一点

到目前为止,这就是我所知道的,但它给了我一个错误:

try
{
    ssh = new SshStream(host, username, password);

    Console.WriteLine("OK ({0}/{1})", ssh.Cipher, ssh.Mac);
    Console.WriteLine("Server version={0}, Client version={1}", ssh.ServerVersion, ssh.ClientVersion);
    Console.WriteLine("-Use the 'exit' command to disconnect.");
    Console.WriteLine();

    //Sets the end of response character
    ssh.Prompt = "#";
    //Remove terminal emulation characters
    ssh.RemoveTerminalEmulationCharacters = true;

    //Reads the initial response from the SSH stream
    Console.Write(ssh.ReadResponse());      // Blocking here

    while (true)
    {
        string command = Console.ReadLine();
        if (command.ToLower().Equals("exit"))
            break;

        //Write command to the SSH stream
        ssh.Write(command);
        //Read response from the SSH stream
        Console.Write(ssh.ReadResponse());
    }
}
catch(Exception e)
{
    Console.WriteLine(e.Message);
}

if(ssh != null)
{
    ssh.Close();
}
我已经添加了Tamir.SharpSSH.dll作为对项目的引用,我正在项目中使用它。SharpSSH还包括另外两个dll,我是否也需要将它们添加到引用中?我看到的示例仅以Tamir.SharpSSH.dll作为参考

我不知道如何在正确的位置启动连接,以及如何向ssh正确提交命令

更新

我意识到在结束程序之前需要关闭SSH连接。错误不再存在,但是,我仍然无法从“ls”命令获取任何信息

更新


我用现在的代码更新了代码。看起来ssh.ReadResponse()正在阻塞,这让我相信服务器没有响应。正确吗?

您能否编辑您的问题,将读取ls命令输出的代码包括在内?@Kenster I更新了代码。由于某种原因,ssh.ReadResponse()挂起。我不确定我是否正确设置了连接。