使用 ScpClient 在 C# 中连接到 ESXi 6.0 和文件传输

Connection to ESXi 6.0 and file transfer in C# using ScpClient

我想连接到 Esxi 6.0 管理程序并上传文件。我使用来自 this topic.

的 SSH 网络
        using (var scp = new ScpClient("10.8.58.26", 22, "root", "MyPasword"))
        {
            scp.Connect();
        }

但我收到 "No suitable authentication method found to complete authentication." 异常。虚拟机管理程序上的 SSH 已打开,我可以手动使用 putty 或 winscp 进行连接。我用 linux 试过了,它正在工作。 我应该如何正确验证 esxi?

进一步研究得出:"ESXi does not use a full featured ssh-server like the well known openssh. It instead uses a lightweight version which is build into Busybox."

我自己想办法。我使用 winscp 库而不是 scp。代码如下所示:

SessionOptions sessionOptions= new SessionOptions
{
    Protocol = Protocol.Sftp,
    HostName = "xxx.xxx.xxx.xxx",
    UserName = "root",
    Password = "MyPasword",
    SshHostKeyFingerprint = "ssh-rsa 2048 xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx"
};

private void WinScp(SessionOptions sessionOptions, string sourceFilePath, string destinationFilePath)
        {
            using (Session session = new Session())
            {
                // Connect
                session.Open(sessionOptions);

                //// Upload files
                TransferOptions transferOptions = new TransferOptions();
                transferOptions.TransferMode = TransferMode.Binary;

                TransferOperationResult transferResult;
                transferResult = session.PutFiles(sourceFilePath, destinationFilePath, true, transferOptions);

                //// Throw on any error
                transferResult.Check();
            }
        }

SshHostKeyFingerprint 可以在 ESXi 的 "Customize System/View Logs" -> "View Support Information" 中找到。