Exemplo n.º 1
0
        public void CopyFileFromGuestToHost(string guestPath, string hostPath, string exclude)
        {
            switch (_copyMethod)
            {
            case CopyMethod.network:
                string guestRootPath = Path.GetPathRoot(guestPath);
                MappedNetworkDriveInfo mappedNetworkDriveInfo = new MappedNetworkDriveInfo(guestRootPath);
                mappedNetworkDriveInfo.Username = _username;
                mappedNetworkDriveInfo.Password = _password;
                mappedNetworkDriveInfo.Auto     = false;
                ConsoleOutput.WriteLine(" Mapping 'Remote:{0}' as '{1}'", mappedNetworkDriveInfo.RemotePath, _username);
                if (!_simulationOnly)
                {
                    using (MappedNetworkDrive mappedNetworkDrive = new MappedNetworkDrive(_vm, mappedNetworkDriveInfo))
                    {
                        string guestNetworkPath     = mappedNetworkDrive.GuestPathToNetworkPath(guestPath);
                        string guestNetworkRootPath = mappedNetworkDrive.GuestPathToNetworkPath(guestRootPath);
                        ConsoleOutput.WriteLine(" Resolving 'Remote:{0}'", guestNetworkRootPath);
                        mappedNetworkDrive.MapNetworkDrive();
                        ConsoleOutput.WriteLine(" Copying 'Remote:{0}' => '{1}'", guestNetworkPath, hostPath);
                        CopyFiles(guestNetworkPath, hostPath, exclude);
                    }
                }
                break;

            case CopyMethod.vmware:
            default:
                ConsoleOutput.WriteLine(" 'Remote:{0}' => '{1}'", guestPath, hostPath);
                if (!_simulationOnly)
                {
                    _vm.CopyFileFromGuestToHost(guestPath, hostPath);
                }
                break;
            }
        }
 public void TestMapCDrive()
 {
     foreach (IVMWareTestProvider provider in _test.Providers)
     {
         MappedNetworkDriveInfo mappedNetworkDriveInfo = new MappedNetworkDriveInfo();
         mappedNetworkDriveInfo.RemotePath = @"C:\";
         mappedNetworkDriveInfo.Username   = provider.Username;
         mappedNetworkDriveInfo.Password   = provider.Password;
         Console.WriteLine("Remote IP: {0}", provider.VirtualMachine.GuestVariables["ip"]);
         using (MappedNetworkDrive mappedNetworkDrive = new MappedNetworkDrive(
                    provider.PoweredVirtualMachine, mappedNetworkDriveInfo))
         {
             string guestWindowsPath = mappedNetworkDrive.GuestPathToNetworkPath(@"C:\Windows");
             Console.WriteLine("Mapped windows directory: {0}", guestWindowsPath);
             Shell guestShell = new Shell(provider.PoweredVirtualMachine);
             Assert.AreEqual(string.Format(@"\\{0}\C$\Windows", guestShell.IpAddress), guestWindowsPath);
             Console.WriteLine(mappedNetworkDrive.NetworkPath);
             Assert.IsTrue(Directory.Exists(guestWindowsPath));
         }
     }
 }
 public void CopyFromHostToGuestWithoutVixCOMSample()
 {
     #region Example: Copying Files to/from the Guest Operating System Without VixCOM
     // connect to a local virtual machine and power it on
     VMWareVirtualHost virtualHost = new VMWareVirtualHost();
     virtualHost.ConnectToVMWareWorkstation();
     VMWareVirtualMachine virtualMachine = virtualHost.Open(@"C:\Users\dblock\Virtual Machines\Windows XP Pro SP3 25GB\WinXP Pro SP3 25GB.vmx");
     virtualMachine.PowerOn();
     virtualMachine.WaitForToolsInGuest();
     // map the C:\ drive (\\guest\c$)
     MappedNetworkDriveInfo info = new MappedNetworkDriveInfo();
     info.RemotePath = @"C:\";
     info.Username   = @"dblock-blue\Administrator";
     info.Password   = @"admin123";
     MappedNetworkDrive mappedNetworkDrive = new MappedNetworkDrive(virtualMachine, info);
     string             hostFile           = @"C:\WINDOWS\win.ini";
     string             guestFile          = mappedNetworkDrive.GuestPathToNetworkPath(@"C:\host-win.ini");
     Console.WriteLine(guestFile);
     File.Copy(hostFile, guestFile);
     #endregion
 }