简体   繁体   中英

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? Because I always get exception when I call MakeDirectoryInGuest().Many thanks.

_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.Username = "admin";

Then,it's work.

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