예제 #1
0
        public void FileTransferToGuest(string guestFilePath, string localFilePath, bool overwrite)
        {
            //throw new NotImplementedException();
            //var fileAttributes = new GuestWindowsFileAttributes()
            //{
            //    accessTime = System.DateTime.Now,
            //    modificationTime = System.DateTime.Now
            //};

            GuestWindowsFileAttributes fileAttributes = new GuestWindowsFileAttributes();

            System.IO.FileInfo fi = new System.IO.FileInfo(localFilePath);

            string fileUploadUrl = _vimService.InitiateFileTransferToGuest(
                _morFileManager,             //VimLib.VimServiceReference.ManagedObjectReference _this,
                _morVM,                      //VimLib.VimServiceReference.ManagedObjectReference vm,
                _NamePasswordAuthentication, //VimLib.VimServiceReference.GuestAuthentication auth,
                guestFilePath, fileAttributes, fi.Length, overwrite
                );

            WebClient webClient = new WebClient();

            byte[] response     = webClient.UploadFile(fileUploadUrl, "PUT", localFilePath);
            string responseText = Encoding.UTF8.GetString(response);
        }
예제 #2
0
 static void UploadFile(NamePasswordAuthentication creds, string source, string destination)
 {
     try
     {
         byte[] data            = System.IO.File.ReadAllBytes(source);
         var    fileTransferUrl = vim.InitiateFileTransferToGuest(guestFileManager, vm, creds, destination, new GuestFileAttributes(), data.Length, true);
         using (var client = new System.Net.WebClient())
         {
             client.CachePolicy = new HttpRequestCachePolicy(HttpRequestCacheLevel.NoCacheNoStore);
             Log("[x] Starting upload of " + source + " to " + destination + "...");
             client.UploadFile(fileTransferUrl, "PUT", source);
             Log("[x] Uploaded " + source + " to " + destination + " on the guest");
         }
     }
     catch (Exception fault)
     {
         Error(fault);
     }
 }