简体   繁体   中英

VMware vCenter API with C# - InitiateFileTransferToGuest fails

I'm trying to use the InitiateFileTransferToGuest method to send a file to a VM. Unfortunately, I'm getting stuck. Here's the related code where VClient is the VimClient with an already successfull connection:

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. 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.

If I remove that validation, I get the same error when trying to run InitiateFileTransferToGuest. I've been browsing the API documentation, and threads in VMware forums and a lot of places to be honest. 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#. 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:

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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