Skip to content

Instantly share code, notes, and snippets.

@jessepeterson
Created December 22, 2015 20:29
Show Gist options
  • Save jessepeterson/9ac458875be09aa4346c to your computer and use it in GitHub Desktop.
Save jessepeterson/9ac458875be09aa4346c to your computer and use it in GitHub Desktop.
ESXi datastore upload helper (uses curl)
#!/bin/sh
if [ $# -lt 5 ]; then
echo "$0 <host> <user> <datastore> <folder> <filepath>"
echo
echo " examples:"
echo " $0 10.0.0.1 root datastore1 ISOs /tmp/Linux.iso"
exit 1
fi
host="$1"
user="$2"
datastore="$3"
folder="$4"
filepath="$5"
filename="`basename $filepath`"
url="https://${host}/folder/${folder}/${filename}?dcPath=ha-datacenter&dsName=${datastore}"
echo "Uploading $filepath"
echo " to $datastore/$folder"
echo " on $host as $user"
curl -v \
-k \
-X PUT \
-T "$filepath" \
-u "$user" \
"$url"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment