How to use GuestFileManager with Vsphere api?

248 views Asked by At

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);
1

There are 1 answers

0
pen On

The wrong place is


auth.Password = "password";
auth.Username = "admin";

Then,it's work.