Using vifs to Manipulate Files on Remote ESXi Hosts
In most cases, vmkfstools and other commands are used to manipulate virtual machine files. In some cases, you might have to view and manipulate files on remote ESXi hosts directly.
Caution If you manipulate files directly, your vSphere setup might end up in an inconsistent state. Use the vSphere Web Client or one of the other vCLI commands to manipulate virtual machine configuration files and virtual disks.
The vifs command performs common operations such as copy, remove, get, and put on ESXi files and directories. The command is supported against ESXi hosts but not against vCenter Server systems.
Some similarities between vifs and DOS or UNIX/Linux file system management utilities exist, but there are many differences. For example, vifs does not support wildcard characters or current directories and, as a result, relative pathnames. Use vifs only as documented.
Instead of using the vifs command, you can browse datastore contents and host files by using a Web browser. Connect to the following location:
http://ESX_host_IP_Address/host
http://ESX_host_IP_Address/folder
You can view datacenter and datastore directories from this root URL. For example:
http://<ESXi_addr>/folder?dcPath=ha-datacenter
http://<ESXi_host_name>/folder?dcPath=ha-datacente
The ESXi host prompts for a user name and password.
The vifs command supports different operations for the following groups of files and directories. Different operations are available for each group, and you specify locations with a different syntax. The behavior differs for vSphere 4.x and vSphere 5.0.
Host configuration files. You must specify the file’s unique name identifier.
Host configuration files. You must specify the file’s unique name identifier.
The /tmp directory and files in that directory.
Specify temp locations by using the /tmp/dir/subdir syntax.
Datastore prefix style: '[ds_name] relative_path'. For example:
URL style: /folder/dir/subdir/file?dsName=<name>. For example:
To avoid problems with directory names that use special characters or spaces, enclose the path in quotes for both operating systems.
When you run vifs, you can specify the operation name and argument and one of the standard connection options. Use aliases, symbolic links, or wrapper scripts to simplify the invocation syntax.
Options
vifs command-specific options allow you to retrieve and upload files from the remote host and perform a number of other operations. All vifs options work on datastore files or directories. Some options also work on host files and files in the temp directory. You must also specify connection options.
- -copy
-c <source> <target>
Copies a file in a datastore to another location in a datastore. The <source> must be a remote source path, the <target> a remote target path or directory.
The - -force option replaces existing destination files.
copy src_file_path dst_directory_path [- -force]
copy src_file_path dst_file_path [- -force]
- -dir
dir datastore_directory_path
- -force
copy src_file_path dst_file_path [- -force]
- -get
-g <remote_path> <local_path>
Downloads a file from the ESXi host to the machine on which you run vCLI. This operation uses HTTP GET.
get src_dstore_file_path dst_local_file_path
get src_d store_dir_path dst_local_file_path
- -listdc
- -listds
Lists the datastore names on the ESXi system. When multiple data centers are available, use the - -dc (-Z) argument to specify the name of the datacenter from which you want to list the datastore.
vifs - -listds
- -mkdir
Creates a directory in a datastore. This operation fails if the parent directory of dst_datastore_file_path does not exist.
- -move
-m <source> <target>
Moves a file in a datastore to another location in a datastore. The <source> must be a remote source path, the <target> a remote target path or directory.
The - -force option replaces existing destination files.
move src_file_path dst_directory_path [- -force]
move src_file_path dst_file_path [- -force]
- -put
Uploads a file from the machine on which you run vCLI to the ESXi host. This operation uses HTTP PUT.
Datastore Host Temp
put src_local_file_path dst_directory_path
- -rm
- -rmdir
Deletes a datastore directory. This operation fails if the directory is not empty.
Examples
You can use vifs to interact with the remote ESXi or vCenter Server system in a variety of ways. Specify one of the connection options listed in Connection Options in place of <conn_options>. The examples illustrate use on a Linux system, use double quotes instead of single quotes when on a Windows system.
Listing Remote Information
List all data centers on a vCenter Server system with --listdc, using --server to point to the vCenter Server system.
vifs --server <my_vc>--username administrator --password <pswd> --listdc
vifs --server <my_vc> --username administrator --password <pswd> --dc kw-dev --listds
vifs --server <my_ESXi> --username root --password <pswd> --listds
The command lists the names of all datastores on the specified server.
You can use each name that has been returned to refer to datastore paths by using square bracket notation, as follows:
'[my_datastore] dir/subdir/file'
vifs --server <my_ESXi> --username root --password <pswd>--dir '[Storage1]'
vifs --server <my_ESXi> --username root --password <pswd> --dir '[Storage1] WindowsXP'
The command lists the directory content. In this example, the command lists the contents of a virtual machine directory.
Content Listing
_________________
vmware-37.log
vmware-38.log
...
vmware.log
...
winxpPro-sp2.vmdk
winxpPro-sp2.vmx
winxpPro-sp2.vmxf
...
vifs <conn_options> --dir '[osdc-cx700-02]'
The command lists the complete contents of the datastore.
Working with Directories and Files on the Remote Server
vifs --server <my_ESXi> --username root --password <pswd> --mkdir '[Storage1] test'
Remove a directory with --rmdir <remote_dir>.
vifs --server <my_ESXi> --username root --password <pswd> --rmdir '[Storage1] test'.
Forcibly remove a directory with --rmdir --force <remote_dir>.
vifs --server <my_ESXi> --username root --password <pswd> --rmdir '[Storage1] test2' --force
Update a file on the remote server with --put <local_path> <remote_path>.
vifs --server <my_ESXi> --username root --password <pswd>
--put /tmp/testfile '[Storage1] test/testfile'
Retrieve a file from the remote server with --get <remote_path> <local_path>|<local_dir>. The command overwrites the local file if it exists. If you do not specify a file name, the filename of the remote file is used.
vifs --server <my_ESXi> --username root --password <pswd> --get '[Storage1] test/testfile' /tmp/tfile
vifs --server <my_ESXi> --username root --password <pswd> --get '[Storage1] test/testfile' /tmp
vifs --server <my_ESXi> --username root --password <pswd> --rm '[Storage1] test2/testfile'
vifs --server <my_ESXi> --username root --password <pswd> --rm '[Storage1] test2/testfile2' --force
Move a file from one location on the remote server to another location with --move <remote_source_path> <remote_target_path>. If you specify a file name, the file is moved and renamed at the same time.
vifs --server <my_ESXi> --username root --password <pswd> --move '[Storage1] test/tfile' '[Storage1] newfile'
If the target file already exists on the remote server, the command fails unless you use --force.
vifs --server <my_ESXi> --username root --password <pswd> --move '[Storage1] test/tfile2' '[Storage1] test2/tfile' --force
vifs --server <my_ESXi> --username root --password <pswd> --copy '[Storage1] test/tfile' '[Storage1] test/tfile2'
If the target file already exists on the remote server, the command fails unless you use --force.
vifs --server <my_ESXi> --username root --password <pswd> --copy '[Storage1] test/tfile' '[Storage1] test/tfile2' --force
Example Scenario
The following example scenario illustrates other uses of vifs. Specify one of the connection options listed in Connection Options in place of <conn_options>.
To manage files and directories on the remote ESXi system
1
vifs <conn_options> --mkdir '[osdc-cx700-03] vcli_test'
You must specify the precise path; there is no concept of a relative path.
2
vifs <conn_options> - -put /tmp/test_doc '[osdc-cx700-03] vcli_test/test_doc'
3
vifs <conn_options> - -move '[osdc-cx700-03] vcli_test/test_doc'
'[osdc-cx700-03] winxpPro-sp2/test_doc
A message indicates success or failure.
4
The following example retrieves a log file for analysis.
vifs <conn_options> --get '[osdc-cx700-03] winxpPro-sp2/vmware.log' ~user1/vmware.log
5
vifs <conn_options> --rm '[osdc-cx700-03] vcli_test/test_doc'
vifs <conn_options> --rmdir '[osdc-cx700-03] vcli_test'