Created
August 6, 2018 20:23
-
-
Save stefpe/6246d14f90b828c17781af9c58cc9280 to your computer and use it in GitHub Desktop.
Dropbox sync example
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
#!/usr/bin/env bash | |
readonly TOKEN=YOUR_APP_TOKEN | |
readonly DIR=/YOUR_DIR_PATH | |
FILE=$1 | |
BASENAME=$(basename $FILE) | |
if [ -f "$FILE" ]; then | |
# upload file to dropbox | |
CMD="upload $DIR/$BASENAME" | |
HTTP_CODE=$(curl -X POST -sL -w "%{http_code}" --output /dev/null https://content.dropboxapi.com/2/files/upload \ | |
--header "Authorization: Bearer $TOKEN" \ | |
--header "Dropbox-API-Arg: {\"path\": \"$DIR/$BASENAME\",\"mode\": \"add\",\"autorename\": true,\"mute\": false,\"strict_conflict\": false}" \ | |
--header "Content-Type: application/octet-stream" \ | |
--data-binary @$FILE) | |
else | |
# delete file from dropbox | |
CMD="delete $DIR/$BASENAME" | |
HTTP_CODE=$(curl -X POST -sL -w "%{http_code}" --output /dev/null https://api.dropboxapi.com/2/files/delete_v2 \ | |
--header "Authorization: Bearer $TOKEN" \ | |
--header "Content-Type: application/json" \ | |
--data "{\"path\": \"$DIR/$BASENAME\"}") | |
fi | |
echo $CMD | |
echo "Response code => $HTTP_CODE" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment