Transferring files to/from Dropbox using the command line

Transferring files to/from Dropbox using the command line

For an upcoming project I needed to upload files to Dropbox from the command line. There is a tool that supports transfers to & from Dropbox but the setup requires a few coordinated steps. This quick how-to is what you need to get started.

dropbox-uploader.sh is a BASH script (found here) that lets you interact with Dropbox from the command line. It uses an application api and therefore you do not need to supply a username / password when using the script. There is a config file that is needed and the first time you run the script, a wizard will walk you through the creation process. To start, get the script with this command
curl "https://raw.githubusercontent.com/andreafabrizi/Dropbox-Uploader/master/dropbox_uploader.sh" -o dropbox_uploader.sh
Next, make the script runnable with the chmod command
chmod +x ./dropbox_uploader.sh
Then run the script the first time to run the wizard
pi@raspberrypi:~ $ ./dropbox_uploader.sh
You should see:
This is the first time you run this script, please follow the instructions:

1) Open the following URL in your Browser, and log in using your account: https://www.dropbox.com/developers/apps
2) Click on "Create App", then select "Dropbox API app"
3) Now go on with the configuration, choosing the app permissions and access restrictions to your Dropbox folder
4) Enter the "App Name" that you prefer (e.g. MyUploader3054620239326)

Now, click on the "Create App" button.

When your new App is successfully created, please click on the Generate button
under the 'Generated access token' section, then copy and paste the new access token here:

# Access token:

Now go to this URL in a browser (can be on a different computer) https://www.dropbox.com/developers/apps and click on Create app

On the next page click on Dropbox api, App folder (for limited access to a specific folder or full access) and then name the app. The name has to be unique to all Dropbox apps. Click Create app

On the next page nothing needs to be changed. Click the Generate Access Token button to get an api token

The next step may be the hardest part, you need to copy the token to the window where you are running the wizard. Enter the token. You should see:
...
When your new App is successfully created, please click on the Generate button
under the 'Generated access token' section, then copy and paste the new access token here:

# Access token: z32cbbVuFcAAAAAAAGHdGdakgA81ykAyTM_1GjW6PFuc67XzbYLhLTiwSmAZgQ

> The access token is z32cbbVuFcAAAAAAAGHdGdakgA81ykAyTM_1GjW6PFuc67XzbYLhLTiwSmAZgQ. Looks ok? [y/N]: y
The configuration has been saved.

Hit Y when prompted. Setup is complete.
BTW – The token above is not real, don’t try to use it.

Then run a quick test with a small file. Find or create a small file to send to Dropbox. I created a text.txt file and used the following command to send that file to my Dropbox account.
./dropbox_uploader.sh upload test.txt .
The ‘.’ at then end tells the uploader to put the file in the root directory of the app folder OR the root directory of your Dropbox account depending on how your app was configured. Use a browser to verify the file was transferred.

Some important notes. The API token is stored in a file ~/.dropbox_uploader. If you need to use a new api token, just delete that file.

One last note: Raspberry Pi Maker is not affiliated with or otherwise sponsored by Dropbox, Inc.

Submit a Comment

Your email address will not be published. Required fields are marked *