Skip to content

Instantly share code, notes, and snippets.

@sdmcraft
Created November 30, 2017 10:59
Show Gist options
  • Save sdmcraft/033cf7150447d2e6761850df53bcae9a to your computer and use it in GitHub Desktop.
Save sdmcraft/033cf7150447d2e6761850df53bcae9a to your computer and use it in GitHub Desktop.
Script to upload all files in a folder to a server
#!/bin/sh
usage()
{
echo -e "Usage: $0 -i <input folder path containing files to upload> -c <credentials of the server to upload to> -u <url to upload to>" \
"\nExample Usage: ./upload-files.sh -i /src/folder -u http://server.com/path -c user:password" 1>&2; exit 1;
}
while getopts i:u:c: option
do
case "${option}"
in
u) URL=${OPTARG};;
i) SOURCE_FOLDER=${OPTARG};;
c) CREDENTIALS=${OPTARG};;
*) usage;;
esac
done
for UPLOAD_FILE in $SOURCE_FOLDER/*
do
FILENAME=`basename $UPLOAD_FILE`
echo -e '\nInvoking curl with' -u $CREDENTIALS -F "$FILENAME=@$UPLOAD_FILE" $URL
curl -s -o /dev/null -w "%{http_code}" -u $CREDENTIALS -F "$FILENAME=@$UPLOAD_FILE" $URL
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment