Created
November 30, 2017 10:59
-
-
Save sdmcraft/033cf7150447d2e6761850df53bcae9a to your computer and use it in GitHub Desktop.
Script to upload all files in a folder to a server
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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