Copy Content to an ESXi Datastore Using CURL

Situation

You need to quickly copy a large file to an ESXi datastore.

Solution

  1. Download a curl version with support for SSL, or download the attached version
  2. Extract the zip file
  3. Take note of the location of the curl.exe file, and the file you want to copy
  4. Open a command prompt, and run the command

Example

Note: curl is case sensitive

c:\curl\curl.exe -u root -v -k -T "fileToUpload.iso" https://xx.xx.xx.xx/folder/fileToUpload.iso/?dsName=NameOfDatastore

OR

c:\>curl\curl\curl.exe -u root -v -k -T "fileToUpload.iso" https://10.10.10.38/folder/ISO/fileToUpload.iso?dsName=ds1

Explanation

c:\curl\curl.exe - Location of the script

-u root -v -k -T - Switches:
-u specifies the user, usually this should be root
-k allows curl to perform insecure SSL connections
-T transfers a specific file to the remote URL

https://xx.xx.xx.xx/folder - Index of Datacenter location. This is the default location of the ESXi URL. This URL must always contain https, an IP address followed by folder. The generic name "folder" is the default for ESX and should not be changed to your the name of the folder on your datastore. You can test to make sure you have the correct address by opening the location in a web browser. https://10.10.10.38/folder brings me to my Index of Datacenters.

/folder/fileToUpload.iso/ or /folder/ISO/fileToUpload.iso - You have to be careful about where you put trailing "/" when using this script. If you wish to copy a file to the root directory of a datastore, you must use a trailing "/". If you want to copy a file to a folder within a datastore, do not use the trailing "/".

?dsName=NameOfDatastore - Everything after the "?" contains information about the datastore. dsName=ds1 indicates that I have a datastore on my ESXi machine named ds1.

More Information

See the curl.pdf file attached to this document for more information about switches and syntax. There is also a plethora of information online.