【问题标题】:VMware vCenter API with C# - InitiateFileTransferToGuest fails使用 C# 的 VMware vCenter API - InitiateFileTransferToGuest 失败
【发布时间】:2015-11-12 13:08:13
【问题描述】:

我正在尝试使用 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 方法时出现第一个错误。我收到这条消息:

VMware.Vim.dll 中出现“VMware.Vim.VimException”类型的未处理异常附加信息:请求引用了意外或未知类型。

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

【问题讨论】:

    标签: c# api vmware


    【解决方案1】:

    我在测试和编造东西后使它工作。我猜测 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);
    

    现在它正在工作,我不知道如何。

    【讨论】:

    • 谢谢!也为我工作。非常感谢先前对此的研究。
    猜你喜欢
    • 2016-11-20
    • 1970-01-01
    • 2017-08-23
    • 2021-08-07
    • 1970-01-01
    • 1970-01-01
    • 2020-08-23
    • 2021-03-23
    • 1970-01-01
    相关资源
    最近更新 更多