Date created: Wednesday, December 4, 2013 3:43:46 PM. Last modified: Thursday, August 2, 2018 9:03:04 AM

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