43

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?

Roger
  • 7,535
  • 5
  • 41
  • 63
  • 4
    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 08 '17 at 18:29
  • The close vote is not for "not a programming language", but asking for an off-site resource. – Benjamin W. Feb 08 '17 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 08 '17 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. – Benjamin W. Feb 08 '17 at 19:03

3 Answers3

56

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.

Graham
  • 7,431
  • 18
  • 59
  • 84
Greg
  • 16,359
  • 2
  • 34
  • 44
  • 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 08 '17 at 18:35
  • 1
    Yes, you can find more information on the different permissions here: https://www.dropbox.com/developers/reference/developer-guide#app-permissions – Greg Feb 08 '17 at 18:51
  • Thanks. I thought so :( The app is working, but it doesn't allow to share the folder. Sigh. And i don't want to expose all my files (via a token) on some server. – Roger Feb 08 '17 at 18:58
  • 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 04 '18 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 '18 at 19:38
  • Currently this doesn't seem to work. I'm just trying to put some backups on dropbox... every try fails with obscure error messages... sometimes confilct, somtimes a more generic error :( – Hoelli Oct 29 '21 at 11:49
16

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

Yash Kant
  • 458
  • 1
  • 6
  • 11
  • 2
    This is the best answer, since it uses the official Dropbox command-line interface. The binaries are available at [https://github.com/dropbox/dbxcli/releases](https://github.com/dropbox/dbxcli/releases) – maurera Nov 13 '20 at 23:05
  • As of March 2023, the repo says it is **not** official: https://github.com/dropbox/dbxcli/commit/dfcfa136ea5799206b4dfc02ef2dedd1b93914dc – user137369 Aug 10 '23 at 23:35
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.

Zaccharie Ramzi
  • 2,106
  • 1
  • 18
  • 37
  • 1
    many people say it does not work for now https://github.com/andreafabrizi/Dropbox-Uploader/issues/498 – cronfy Aug 11 '20 at 06:58
  • yes I see that, when I used it it worked perfectly fine. Some say you need to use [another API](https://github.com/andreafabrizi/Dropbox-Uploader/issues/498#issuecomment-674011792) – Zaccharie Ramzi Aug 17 '20 at 09:43
  • I just used it now and it worked perfectly. I am using a token I used back in May that is still working. – Zaccharie Ramzi Aug 18 '20 at 09:08
  • @YashKant could you copy-paste the error trace, if any, for reference? – Zaccharie Ramzi Oct 06 '20 at 12:15
  • @ZaccharieRamzi: The error was also quite unhelpful, it said "Some error occured. Please check the log". And I could not find a log file as well [https://github.com/andreafabrizi/Dropbox-Uploader/issues/509]. What worked was this: https://github.com/dropbox/dbxcli – Yash Kant Oct 06 '20 at 23:29
  • Happy to see that at least there exists a backup solution, although it doesn't seem maintained either. For the record, I just used Dropbox-Uploader and it worked just fine. Maybe we could compare our setups. – Zaccharie Ramzi Oct 07 '20 at 08:03
  • 1
    Wow, that's a fine working solution! – Hoelli Oct 30 '21 at 05: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 06 '23 at 23:33