Curl Backup with Login Example

Download backups via HTTP/S using curl, from sites that set a cookies via a PHP login form


# Create a cookie by logging in via PHP form
curl -k -s -o /dev/null --cookie cjar --cookie-jar cjar --data "Login=myusername&Pass=53cr373" --location

# Grab the session ID from the cookie jar, it needs to be in the request for the backup file
sessionID=`grep SessionID cjar | awk {'print $NF'}`

# Get the backup
curl -k -s -o ./Backup-`date '+%Y-%m-%d--%H-%M-%S'`.rar --cookie cjar --cookie-jar cjar --location\&Session=$sessionID

# Log out
curl -k -s -o /dev/null --cookie cjar --cookie-jar cjar

# Delete cookie jay
rm cjar