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
git clone https://github.com/andreafabrizi/Dropbox-Uploader.git
Step 2: Setup Dropbox Uploader
cd Dropbox-Uploader chmod +x dropbox_uploader.sh ./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.
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
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.
#!/usr/bin/python from subprocess import Popen,PIPE import time, os, subprocess import psutil import glob import fnmatch import subprocess import shutil def dropbox_upload(): is_valid=0 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.split(": ")) 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/' else: is_valid = 1 command = '' print 'EXITING UPLOADER' os.system(command) if __name__ == '__main__': dropbox_upload()
- upload <LOCAL_FILE/DIR …> <REMOTE_FILE/DIR>
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 <REMOTE_FILE/DIR> [LOCAL_FILE/DIR]
Download file or directory from Dropbox to a local folder
- delete <REMOTE_FILE/DIR>
Remove a remote file or directory from Dropbox
- move <REMOTE_FILE/DIR> <REMOTE_FILE/DIR>
Move or rename a remote file or directory
- copy <REMOTE_FILE/DIR> <REMOTE_FILE/DIR>
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 the script from your Dropbox account
- -f <FILENAME>
Load the configuration file from a specific file
Skip already existing files when download/upload. Default: Overwrite
Enable DEBUG mode
Quiet mode. Don’t show progress meter or messages
Show cURL progress meter
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