Raspberry Pi Dropbox Uploader in Python

This tutorial will show you how to create a Raspberry Pi Dropbox Uploader in Python. It is based off of Andrea Fabrizi’s github project.

Start: Raspberry Pi Dropbox Uploader Tutorial

Step 1: Download the github project to your Raspberry Pi /home/pi Directory

Run this:

git clone https://github.com/andreafabrizi/Dropbox-Uploader.git



Step 2: Setup Dropbox Uploader

cd Dropbox-Uploader
chmod +x dropbox_uploader.sh

A configuration wizard will walk you through the necessary setup for the Dropbox App. Head to https://www.dropbox.com/developers/apps to create a new Dropbox App. I chose these settings:



You will need this information:



Step 3: Using the Uploader

I am going to create a test file to upload.

nano test.txt

Then enter some random text and exit with CTRL-X, press y, and then hit enter. To see what files we have to work with run the command

./dropbox_uploader.sh list

To create a directory in your Dropbox run the command:

./dropbox_uploader.sh mkdir /Apps/PythonUploader

I will be creating a directory in /Apps/ and then uploading files to that directory.

./dropbox_uploader.sh list Apps


You should then be able to go to your Dropbox account and see the PythonUploader folder in the Apps directory. /Apps/PythonUploader.



Let’s upload our test file by running the command:

./dropbox_uploader.sh upload test.txt /Apps/PythonUploader


Step 4: Python Scripts Using the Dropbox Uploader

I will be creating several python scripts that have different functions for uploading files to Dropbox. Here is a script that will ask the user for different parameters based on what they would like to do with their Dropbox.

from subprocess import Popen,PIPE
import time, os, subprocess
import psutil
import glob
import fnmatch
import subprocess
import shutil

def dropbox_upload():
	while not is_valid :
		try :
			print (2 * '\n')
			print (30 * '-')
			print ("   DROPBOX MENU")
			print (30 * '-')
			print ("1. Upload")
			print ("2. Make Directory")
			print ("3. List")
			print ("4. Exit")
			print (30 * '-')		
			choice = int ( raw_input('Enter your choice [1-3] : ') )
			print (2 * '\n')

		except ValueError, e :
			print ("'%s' is not a valid integer." % e.args[0].split(": ")[1])
		print '\n'		
		if choice == 1:
			files = [f for f in os.listdir('.') if os.path.isfile(f)]
			for f in files:
				print f	
			print '\n'
			nameOfFile = raw_input("Enter name of file to upload: ")
			fullDirectory = '/home/pi/Dropbox-Uploader/' + nameOfFile
			command = '/home/pi/Dropbox-Uploader/dropbox_uploader.sh upload ' + fullDirectory + ' /Apps/PythonUploader/'

		elif choice == 2:
			directoryToMake = raw_input("Enter name of directory to be created: ")
			command = '/home/pi/Dropbox-Uploader/dropbox_uploader.sh mkdir /Apps/' + directoryToMake 

		elif choice == 3:
			print "Listing Directory Contents"
			command = '/home/pi/Dropbox-Uploader/dropbox_uploader.sh', 'list /Apps/'
			is_valid = 1
			command =  ''



if __name__ == '__main__':




Full Documentation

    Upload a local file or directory to a remote Dropbox folder.
    If the file is bigger than 150Mb the file is uploaded using small chunks (default 4Mb); in this case a . (dot) is printed for every chunk successfully uploaded and a * (star) if an error occurs (the upload is retried for a maximum of three times). Only if the file is smaller than 150Mb, the standard upload API is used, and if the -p option is used the default curl progress bar is displayed during the upload process.
    The local file/dir parameter supports wildcards expansion.
    Download file or directory from Dropbox to a local folder
  • delete <REMOTE_FILE/DIR>
    Remove a remote file or directory from Dropbox
    Move or rename a remote file or directory
    Copy a remote file or directory
  • mkdir <REMOTE_DIR>
    Create a remote directory on DropBox
  • list [REMOTE_DIR]
    List the contents of the remote Dropbox folder
  • share <REMOTE_FILE>
    Get a public share link for the specified file or directoryinfo
  • Print some info about your Dropbox account
  • unlink
    Unlink the script from your Dropbox account

Optional parameters:

  • -f <FILENAME>
    Load the configuration file from a specific file
  • -s
    Skip already existing files when download/upload. Default: Overwrite
  • -d
    Enable DEBUG mode
  • -q
    Quiet mode. Don’t show progress meter or messages
  • -p
    Show cURL progress meter
  • -k
    Doesn’t check for SSL certificates (insecure)


./dropbox_uploader.sh upload /etc/passwd /myfiles/passwd.old
./dropbox_uploader.sh upload *.zip /
./dropbox_uploader.sh download /backup.zip
./dropbox_uploader.sh delete /backup.zip
./dropbox_uploader.sh mkdir /myDir/
./dropbox_uploader.sh upload "My File.txt" "My File 2.txt"
./dropbox_uploader.sh share "My File.txt"
./dropbox_uploader.sh list




2 Responses

  1. jack says:

    hey this is great,
    Just wondering what changes would I need to make in order to run this from the crontab -e, @reboot

  1. February 28, 2018

    […] The Pi Hut The Raspbian Operating System Download PuTTY Want to upload your files to Dropbox instead? I’ve tried this and it worked for me, although it is a bit fiddly […]

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.