简体   繁体   English

如何在Vsphere API中使用GuestFileManager?

[英]How to use GuestFileManager with Vsphere api?

I would like to ask how to create a directory on the guest VM by using GuestFileManager?Could someone provide example code? 我想问一下如何使用GuestFileManager在来宾VM上创建目录吗?有人可以提供示例代码吗? Because I always get exception when I call MakeDirectoryInGuest().Many thanks. 因为我在调用MakeDirectoryInGuest()时总是会遇到异常。非常感谢。

_service = _client.Connect(_hostName);
NameValueCollection nvcFilter = new NameValueCollection();
nvcFilter.Add("Name", "W81x64");
_vm = (VirtualMachine)_client.FindEntityView(typeof(VirtualMachine), null, nvcFilter, null);

 string DirectoryPath = @"C:\TestFolder\";
 NamePasswordAuthentication auth = new NamePasswordAuthentication();
 auth.Password = "admin";
 auth.Username = "password";
 auth.InteractiveSession = false;
 GuestFileManager guestfilemgr = new GuestFileManager(VimClient, _service.FileManager);
 guestfilemgr.MakeDirectoryInGuest(_vm.Runtime.Host,auth, DirectoryPath, true);

The wrong place is 错误的地方是


auth.Password = "password"; auth.Password =“密码”;
auth.Username = "admin"; auth.Username =“ admin”;

Then,it's work. 然后,它的工作。

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

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