46

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?

4
  • 5
    Oh here we go again. Bash is a programming language. If i put it on serverfault they close it since its programming. Please give me a break :/
    – Roger
    Feb 8, 2017 at 18:29
  • The close vote is not for "not a programming language", but asking for an off-site resource. Feb 8, 2017 at 18:49
  • 2
    Well thats not how the votes where casted. Anyway, its about the dropbox API and I don't see how thats not programming related... Well, what ever makes your boat float. I will remove the question later today.
    – Roger
    Feb 8, 2017 at 19:00
  • Yes, that's how they were cast. "Request for off-site resource" is one of the choices within "Off-topic". The question is also very broad: a solution would have to encompass a complete Bash/shell script, and it's also not very clear: "something like curl", "good hint" aren't super specific, to be honest. Feb 8, 2017 at 19:03

3 Answers 3

61

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\", \"mode\": \"overwrite\", \"strict_conflict\": false}" \
    --header "Content-Type: application/octet-stream" \
    --data-binary @matrices.txt

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

8
  • 1
    thanks! That means full access. So in any case of a break-in, via that token you can basically access all my files?
    – Roger
    Feb 8, 2017 at 18:35
  • 1
    Yes, you can find more information on the different permissions here: dropbox.com/developers/reference/…
    – Greg
    Feb 8, 2017 at 18:51
  • 1
    @Roger you can create an app that deals with only one directory so you are not exposing all you data on dbox
    – El Don
    Jan 4, 2018 at 14:05
  • 1
    And make sure not to miss the @ before the filename, as it tells curl to upload the contents of the file and not the filename
    – Brimstedt
    Dec 29, 2018 at 19:38
  • 1
    This solution worked well for me. However, there is a size limit of 150 MB. That was ok for me, I could just split the file. If that's not enough, you can upload up to 350 GB via an upload session.
    – slp
    Oct 6, 2023 at 15:29
19

@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.

3
1

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.

8
  • 1
    many people say it does not work for now github.com/andreafabrizi/Dropbox-Uploader/issues/498
    – cronfy
    Aug 11, 2020 at 6:58
  • yes I see that, when I used it it worked perfectly fine. Some say you need to use another API Aug 17, 2020 at 9:43
  • I just used it now and it worked perfectly. I am using a token I used back in May that is still working. Aug 18, 2020 at 9:08
  • 1
    Wow, that's a fine working solution!
    – Hoelli
    Oct 30, 2021 at 5:34
  • 1
    For what it's worth, I just tried this script today (February 2023) and it still works absolutely fine! Very happy with this solution 👍
    – RocketNuts
    Feb 6, 2023 at 23:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.