简体   繁体   English

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

[英]VMware vCenter API with C# - InitiateFileTransferToGuest fails

I'm trying to use the InitiateFileTransferToGuest method to send a file to a VM. 我正在尝试使用InitiateFileTransferToGuest方法将文件发送到VM。 Unfortunately, I'm getting stuck. 不幸的是,我陷入困境。 Here's the related code where VClient is the VimClient with an already successfull connection: 这是相关代码,其中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);   

First error shows up when getting to the ValidateCredentialsInGuest method. 到达ValidateCredentialsInGuest方法时出现第一个错误。 I get this message: 我收到这条消息:

An unhandled exception of type 'VMware.Vim.VimException' occurred in VMware.Vim.dll Additional information: The request refers to an unexpected or unknown type. VMware.Vim.dll中出现类型为“VMware.Vim.VimException”的未处理异常附加信息:请求指的是意外或未知类型。

If I remove that validation, I get the same error when trying to run InitiateFileTransferToGuest. 如果我删除了该验证,则在尝试运行InitiateFileTransferToGuest时会出现相同的错误。 I've been browsing the API documentation, and threads in VMware forums and a lot of places to be honest. 我一直在浏览API文档,以及VMware论坛和很多地方的线程。 The only pieces of code I've seen posted where it works were in Java and Perl, but the API implementation is a little different than C#. 我见过的唯一代码片段是在Java和Perl中使用的,但API实现与C#略有不同。 Any idea where to look? 知道在哪里看? Thank you! 谢谢!

I made it work after testing and making up stuff. 我在测试和编写东西之后就开始工作了。 I guessed the MoRef for both AuthManager and FileManager doing the following: 猜想 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);

Now it's working, and I have no idea how. 现在它正在运作,我不知道如何。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM