我尝试使用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.VimException'发生在VMware.Vim.dll中的附加信息:请求指的是意外或未知类型。
如果我删除了该验证,则在尝试运行InitiateFileTransferToGuest时会出现相同的错误。我一直在浏览API文档,并在VMware论坛和很多地方使用线程来说实话。我见过的唯一代码片段是在Java和Perl中发布的,但API实现与C#略有不同。知道在哪里看? 谢谢!
答案 0 :(得分:2)
我在测试和编写东西之后就开始工作了。我 猜测 AutReManager和FileManager的MoRef执行以下操作:
ManagedObjectReference MoRefFileManager = new ManagedObjectReference("guestOperationsFileManager");
GuestFileManager VMFileManager = new GuestFileManager(VClient, MoRefFileManager);
ManagedObjectReference MoRefAuthManager = new ManagedObjectReference("guestOperationsAuthManager");
GuestAuthManager VMAuthManager = new GuestAuthManager(VClient, MoRefAuthManager);
现在它正在工作,我不知道如何。