gpt4 book ai didi

c# - 使用 C# 的 VMware vCenter API - InitiateFileTransferToGuest 失败

转载 作者:行者123 更新时间:2023-11-30 16:51:38 29 4
gpt4 key购买 nike

我正在尝试使用 InitiateFileTransferToGuest 方法将文件发送到 VM。不幸的是,我被卡住了。这是相关代码,其中 VClient 是已经成功连接的 VimClient:

GuestOperationsManager VMOpsManager = new GuestOperationsManager(VClient, VClient.ServiceContent.GuestOperationsManager);
GuestFileManager VMFileManager = new GuestFileManager(VClient, VClient.ServiceContent.FileManager);
GuestAuthManager VMAuthManager = new GuestAuthManager(VClient, VClient.ServiceContent.AuthorizationManager);

NamePasswordAuthentication Auth = new NamePasswordAuthentication()
{
Username = "username",
Password = "password",
InteractiveSession = false
};

VMAuthManager.ValidateCredentialsInGuest(CurrentVM.MoRef, Auth);

System.IO.FileInfo FileToTransfer = new System.IO.FileInfo("C:\\userlist.txt");
GuestFileAttributes GFA = new GuestFileAttributes()
{
AccessTime = FileToTransfer.LastAccessTimeUtc,
ModificationTime = FileToTransfer.LastWriteTimeUtc
};

string TransferOutput = VMFileManager.InitiateFileTransferToGuest(CurrentVM.MoRef, Auth, "C:\\userlist.txt", GFA, FileToTransfer.Length, false);

进入 ValidateCredentialsInGuest 方法时出现第一个错误。我收到此消息:

An unhandled exception of type 'VMware.Vim.VimException' occurred in VMware.Vim.dll Additional information: The request refers to an unexpected or unknown type.

如果我删除该验证,我在尝试运行 InitiateFileTransferToGuest 时会遇到同样的错误。老实说,我一直在浏览 API 文档和 VMware 论坛中的主题以及很多地方。我看到的唯一代码片段是用 Java 和 Perl 发布的,但 API 实现与 C# 略有不同。知道在哪里看吗?谢谢!

最佳答案

我在测试和编造东西后让它工作。我猜测 AuthManager 和 FileManager 的 MoRef 执行以下操作:

ManagedObjectReference MoRefFileManager = new ManagedObjectReference("guestOperationsFileManager");
GuestFileManager VMFileManager = new GuestFileManager(VClient, MoRefFileManager);
ManagedObjectReference MoRefAuthManager = new ManagedObjectReference("guestOperationsAuthManager");
GuestAuthManager VMAuthManager = new GuestAuthManager(VClient, MoRefAuthManager);

现在可以用了,我不知道怎么做。

关于c# - 使用 C# 的 VMware vCenter API - InitiateFileTransferToGuest 失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33672160/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com