49

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 :/ Commented Feb 8, 2017 at 18:29
  • The close vote is not for "not a programming language", but asking for an off-site resource. Commented 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. Commented 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. Commented Feb 8, 2017 at 19:03

3 Answers 3

64

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.

Sign up to request clarification or add additional context in comments.

8 Comments

thanks! That means full access. So in any case of a break-in, via that token you can basically access all my files?
Yes, you can find more information on the different permissions here: dropbox.com/developers/reference/…
@Roger you can create an app that deals with only one directory so you are not exposing all you data on dbox
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
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.
|
20

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

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
As of March 2023, the repo says it is not official: github.com/dropbox/dbxcli/commit/…
They are testing it publicly before making the go SDK (that dbxcli uses) official. But it is made by them (and hosted on their github account)
2

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 Comments

many people say it does not work for now github.com/andreafabrizi/Dropbox-Uploader/issues/498
yes I see that, when I used it it worked perfectly fine. Some say you need to use another API
I just used it now and it worked perfectly. I am using a token I used back in May that is still working.
Wow, that's a fine working solution!
For what it's worth, I just tried this script today (February 2023) and it still works absolutely fine! Very happy with this solution 👍
|

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.