Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Upload file on Linux (CLI) to Dropbox (via bash/sh)?

I need to save (and overwrite) a file via the cron (hourly) to my dropbox account. The file needs to be stored in a predefined location (which is shared with some other users).

I have seen the possibility to create a Dropbox App, but that create its own dropbox folder.

Also looked at Dropbox Saver but that seems for browsers.

I was thinking (hoping) something super lightweight, a long the lines of CURL, so i don't need to install libraries. Just a simple sh script would be awesome. I only need to PUT the file (overwrite), no need to read (GET) it back.

Was going thru the dropbox developer API documentation, but kind of got lost.

Anybody a good hint?

like image 656
Roger Avatar asked Feb 08 '17 18:02

Roger


People also ask

How do I upload files to Dropbox from Linux?

To upload to Dropbox via the Dropbox Uploader, first move the file into /home/Dropbox-Uploader/. Do this with the file manager. Then, to start the upload, simply run the upload, and specify the folder.


3 Answers

First, since you need to access an existing shared folder, register a "Dropbox API" app with "Full Dropbox" access:

https://www.dropbox.com/developers/apps/create

Then, get an access token for your account for your app. The easiest way is to use the "Generate" button on your app's page, where you'll be sent after you create the app. It's also accessible via the App Console.

Then, you can upload to a specified path via curl as shown in this example:

This uploads a file from the local path matrices.txt in the current folder to /Homework/math/Matrices.txt in the Dropbox account, and returns the metadata for the uploaded file:

echo "some content here" > matrices.txt

curl -X POST https://content.dropboxapi.com/2/files/upload \
    --header "Authorization: Bearer <ACCESS_TOKEN>" \
    --header "Dropbox-API-Arg: {\"path\": \"/Homework/math/Matrices.txt\"}" \
    --header "Content-Type: application/octet-stream" \
    --data-binary @matrices.txt

<ACCESS_TOKEN> should be replaced with the OAuth 2 access token.

like image 192
Greg Avatar answered Oct 23 '22 21:10

Greg


@Greg's answer also works but seems like a long chore.

I used Dropbox's official command-line interface here: https://github.com/dropbox/dbxcli.

As the date of posting, it is working fine and provides lots of helpful commands for downloading and uploading.

like image 28
Yash Kant Avatar answered Oct 23 '22 21:10

Yash Kant


Another solution I just tried is a bash utility called Dropbox-Uploader. After configuration through the same steps as above (app creation and token generation), you can just do: ./dropbox_uploader.sh upload mylocal_file my_remote_file, which I find pretty convenient.

like image 1
Zaccharie Ramzi Avatar answered Oct 23 '22 21:10

Zaccharie Ramzi