Created
March 26, 2014 20:36
-
-
Save tonybolzan/9792813 to your computer and use it in GitHub Desktop.
This script enable to send files to a specific folder in your Google Drive Account
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/bash | |
# Google Drive Uploader | |
# | |
# This script enable to send files to a specific folder in your Google Drive Account | |
# You can easily back up your data on Google Drive | |
# | |
# Author Tonin R. Bolzan <tonin@bolzan.io> | |
# License http://www.opensource.org/licenses/mit-license.php MIT License | |
# https://gist.github.com/tonybolzan | |
USER="user@example.com" # Your Email | |
PASS="plaintextpassword" # Your Google Password | |
ACCOUNT="HOSTED" # GoogleApps=HOSTED , gmail=GOOGLE | |
FOLDERID="0v9VrzBNE3qKwdmNGS213eDZzzkU" # ID From URL of the folder in Google Drive | |
if [[ $# -eq 0 ]]; then | |
echo "Usage: $0 filename" | |
exit 1 | |
fi | |
if [[ ! -f "$1" ]]; then | |
echo "File not found" | |
exit 1 | |
fi | |
FILE="$1" | |
FILENAME=`basename $FILE` | |
MIME=`file -b --mime-type $FILE` | |
TOKEN=`curl -s --data-urlencode Email=$USER --data-urlencode Passwd=$PASS -d accountType=$ACCOUNT -d service=writely -d source=cURL "https://www.google.com/accounts/ClientLogin" | grep "Auth=" | cut -d"=" -f2` | |
UPLOADLINK=`curl -s -S -k --request POST -H "Content-Length: 0" -H "Authorization: GoogleLogin auth=${TOKEN}" -H "GData-Version: 3.0" -H "Content-Type: $MIME" -H "Slug: $FILENAME" "https://docs.google.com/feeds/upload/create-session/default/private/full/folder:$FOLDERID/contents?convert=false" -D /dev/stdout | grep "Location:" | sed s/"Location: "//` | |
curl -s -S -k --request POST --data-binary "@$FILE" -H "Authorization: GoogleLogin auth=${TOKEN}" -H "GData-Version: 3.0" -H "Content-Type: $MIME" -H "Slug: $FILE" "$UPLOADLINK" -o /dev/null |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment