Date created: 12/04/13 15:43:46. Last modified: 08/02/18 09:03:04

Curl Backup with Login Example

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

#!/bin/bash

# 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 https://www.website.com/

# 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 http://www.website.com/?createbackup=1\&Session=$sessionID

# Log out
curl -k -s -o /dev/null --cookie cjar --cookie-jar cjar https://www.website.com/?logout=1

# Delete cookie jay
rm cjar