Project

dbox

0.04
No commit activity in last 3 years
No release in over 3 years
There's a lot of open issues
An easy-to-use Dropbox client with fine-grained control over syncs. Think of it as halfway point between the developer API and a normal client, which gives you control over what and when Dropbox syncs but handles all the details.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

Runtime

>= 1.6.2
>= 1.5.3
>= 0.4.5
>= 1.3.3
 Project Readme

dbox

Dropbox integration made easy. This robust client gives you control over what, where, and when you sync with Dropbox.

Available as both a command-line client and a Ruby API.

$ cd /tmp
$ dbox clone Public
$ cd Public
$ echo "Hello World" > hello.txt
$ dbox sync
[INFO] Uploading /Public/hello.txt

IMPORTANT: This is not an automated Dropbox client. It will exit after sucessfully pushing/pulling, so if you want regular updates, you can run it in cron, a loop, etc. If you do want to run it in a loop, take a look at sample_polling_script.rb. You get deterministic control over what you want Dropbox to do and when you want it to happen.

Installation

Install dbox

$ gem install dbox

Get developer keys

  • Follow the instructions at https://www.dropbox.com/developers/quickstart to create a Dropbox development application, and copy the application keys. Unless you get your app approved for production status, these keys will only work with the account you create them under, so make sure you are logged in with the account you want to access from dbox.

  • Now either set the keys as environment variables:

$ export DROPBOX_APP_KEY=cmlrrjd3j0gbend
$ export DROPBOX_APP_SECRET=uvuulp75xf9jffl
  • Or include them in calls to dbox:
$ DROPBOX_APP_KEY=cmlrrjd3j0gbend DROPBOX_APP_SECRET=uvuulp75xf9jffl dbox ...

Generate an access token

  • Make an authorize request:
$ dbox authorize
1. Go to: https://www.dropbox.com/1/oauth2/authorize?client_id=1x7xvn1pvas3a3&response_type=code
2. Click "Allow" (you might have to log in first)
3. Copy the authorization code
Enter the authorization code here: 
  • Visit the given URL in your browser, and then go back to the terminal and enter the code that Dropbox provides.

  • Now either set the keys as environment variables:

$ export DROPBOX_ACCESS_TOKEN=aeDsfS4QaReAAAAAAAAAAbZ6nrUUrXZ_Z4Rct2DVTYp6B14N-qiz189gm2VHQqvD
$ export DROPBOX_USER_ID=230324561
  • Or include the access token in calls to dbox:
$ DROPBOX_ACCESS_TOKEN=aeDsfS4QaReAAAAAAAAAAbZ6nrUUrXZ_Z4Rct2DVTYp6B14N-qiz189gm2VHQqvD dbox ...
  • The access token will last for 10 years, or when you choose to invalidate it, whichever comes first. So you really only need to do this once, and then keep them around.

Using dbox from the Command-Line

Usage

Authorize

$ dbox authorize

Create a new Dropbox folder

$ dbox create <remote_path> [<local_path>]

Clone an existing Dropbox folder

$ dbox clone <remote_path> [<local_path>]

Pull (download changes from Dropbox)

$ dbox pull [<local_path>]

Push (upload changes to Dropbox)

$ dbox push [<local_path>]

Sync (pull changes from Dropbox, then push changes to Dropbox)

$ dbox sync [<local_path>]

Move (move/rename the Dropbox folder)

$ dbox move <new_remote_path> [<local_path>]

Example

$ export DROPBOX_APP_KEY=cmlrrjd3j0gbend
$ export DROPBOX_APP_SECRET=uvuulp75xf9jffl
$ dbox authorize
$ open http://www.dropbox.com/0/oauth/authorize?oauth_token=aaoeuhtns123456
$ export DROPBOX_ACCESS_TOKEN=aeDsfS4QaReAAAAAAAAAAbZ6nrUUrXZ_Z4Rct2DVTYp6B14N-qiz189gm2VHQqvD
$ cd /tmp
$ dbox clone Public
$ cd Public
$ echo "Hello World" > hello.txt
$ dbox push
$ cat ~/Dropbox/Public/hello.txt
Hello World
$ echo "Oh, Hello" > ~/Dropbox/Public/hello.txt
$ dbox pull
$ cat hello.txt
Oh, Hello

Using dbox from Ruby

The Ruby clone, pull, and push APIs return a hash of the changes made during that operation. If any failures were encountered while uploading or downloading from Dropbox, they will be shown in the :failed entry in the hash. Often, trying your operation again will resolve the failures as the Dropbox API occasionally returns errors for valid operations.

{ :created => ["foo.txt"], :deleted => [], :updated => [] :failed => [] }

If any conflicts occur where file contents would be lost, the conflicting file is renamed and the resulting hash has a :conflicts entry. On a push operation, the conflicting file being pushed will be renamed. On a pull, the existing file that would have been overwritten will be renamed and the downloaded file will take the name (as that will keep multiple clients in sync).

{ :created => [], :updated => [], :deleted => [], :conflicts => [{ :original => "foo.txt", :renamed => "foo (1).txt" }], :failed => [] }

The sync API returns a hash with two entries: :push and :pull, which contain the change hashes for the two operations.

Usage

Setup

  • Authorize beforehand with the command-line tool
require "dbox"

Create a new Dropbox folder

Dbox.create(remote_path, local_path)

Clone an existing Dropbox folder

Dbox.clone(remote_path, local_path)

Pull (download changes from Dropbox)

Dbox.pull(local_path)

Push (upload changes to Dropbox)

Dbox.push(local_path)

Sync (pull changes from Dropbox, then push changes to Dropbox)

Dbox.sync(local_path)

Move (move/rename the Dropbox folder)

Dbox.move(new_remote_path, local_path)

Check whether a Dropbox DB file is present

Dbox.exists?(local_path)

Example

$ export DROPBOX_APP_KEY=cmlrrjd3j0gbend
$ export DROPBOX_APP_SECRET=uvuulp75xf9jffl
$ dbox authorize
$ open http://www.dropbox.com/0/oauth/authorize?oauth_token=aaoeuhtns123456
$ export DROPBOX_ACCESS_TOKEN=aeDsfS4QaReAAAAAAAAAAbZ6nrUUrXZ_Z4Rct2DVTYp6B14N-qiz189gm2VHQqvD
$ export DROPBOX_USER_ID=pqej9rmnj0i1gcxr4
> require "dbox"
> Dbox.clone("/Public", "/tmp/public")
> File.open("/tmp/public/hello.txt", "w") {|f| f << "Hello World" }
> Dbox.push("/tmp/public")

> File.read("#{ENV['HOME']}/Dropbox/Public/hello.txt")
=> "Hello World"
> File.open("#{ENV['HOME']}/Dropbox/Public/hello.txt", "w") {|f| f << "Oh, Hello" }

> Dbox.pull("/tmp/public")
> File.read("#{ENV['HOME']}/Dropbox/Public/hello.txt")
=> "Oh, Hello"