How to Copy Files To and From a VMware Server Virtual Machine Guest
Files may be copied to and from the guest operating system running inside a VMware virtual machine using the vmrun command line tool.
Note that in order to perform these tasks, VMware Tools must be installed on the guest operating system. For details on installing VMware Tools refer to the Understanding and Installing VMware Tools chapter of the Virtuatopia VMware Server 2.0 Essentials online book.
Finding the vmrun Tool
The vmrun tool is installed on the host system as part of the VMware Server and VMware Workstation virtualization products. Assuming a standard installation where the software is placed in the default location, the vmrun executable is located in \Program Files\VMware\VMware Server on Windows hosts and in the /usr/bin directory on Linux hosts.
Understanding vmrun Command Line Syntax
The basic command line syntax for using vmrun varies slightly between VMware products, but can generally be summarized as follows:
vmrun host authentication flags guest authentication flags command parameters
The host authentication flags are required to provide host, login and password information for the host system. These are essentially the same credentials that would be used when accessing the VI Web Access management interface. These flags are required only on VMware Server hosts, and are not needed for VMware Workstation:
The corresponding password for the guest user specified using the -gu flag.
The command argument identifies to vmrun the task to be performed on the specified virtual machine. For example, start. stop and reset are all valid commands. Other commands are available to perform tasks within a guest operating system, such as runProgramInGuest and deleteFileInGuest.
The parameters arguments specify optional information required for a specific command. If, for example, the stop command is specified, the parameters argument is used to reference the .vmx file of the virtual machine which is to be powered off. In the case of running guest commands, both the .vmx file of the target virtual machine and the path to the program to be executed must be provided as parameters.
When specifying the virtual machine on which a command is to be executed, the location of the virtual machine .vmx configuration file must be provided. For VMware Workstation, this involves specifying the full path of the file. For example:
In the case of VMware Server 2.0, which introduced the concept of datastores. the name of the datastore in which the virtual machines resides must be provided together with the path of the corresponding .vmx file within that datastore. For example, to reference a virtual machine stored in the win2008 sub-directory of the Vol1 datastore, the vmrun path parameter would be defined as follows (note that the datastore name is enclosed in square brackets and separated from the sub-directory by a space character):
Copying Files to a Virtual Machine Guest
A file may be copied to the guest operating system running in a VMware virtual machine using the copyFileFromHostToGuest command. For example:
Copying Files from a Virtual Machine Guest
A file may be copied from the guest operating system running in a VMware virtual machine using the copyFileFromGuestToHost command. For example:
Checking if a File Exists in a Virtual Machine Guest
Before attempting to copy a file to or from a gust operating system, it may first be useful to check whether the file exists on the guest filesystems. This can quickly be achieved with vmrun and the fileExistsInGuest command. For example: