Some cloud storage providers offer a client application that can be installed in the local storage, allowing for a "local mirror" of the remote storage. Usually this synchronization is two-way, the changes on the local system are propagated to the cloud storage and the changes made in the remote storage are reflected in the local mirror. Dropbox since its inception as such app for such purpose, Google Drive used to have one of these, and OneDrive also have such application. In this article, I will present a ‘proof-of-concept’ Python application that is able to make the "first part" of the synchronize, ie, reproduce the local changes in the remote cloud storage.
Using the official Dropbox Python SDK and the library watchdog, it’s possible to crate one such application in around 100 lines of code.
Watchdog allows you to monitor changes in your local file system through events triggered by those changes like ‘FileCreated’,’FileModified’,’FileDeleted’ or ‘FileMoved’. For each type of event, there one respective method in an EventHandler subclass which should implement these methods.
To use the Dropbox SDK, you’ll have to create one application in the Developer frontend. Generate one access token that can be used in our application.
This application just have two parameters: the local directory where the file changes will occur and the remote directory on Dropbox where these changes should be reflect. It’s a kind of mapping between that local directory and this remote directory.
NOTE: This code does not perform an initial synchronization of the local files to the directory in the cloud. It only uploads file created or changed during the execution of the program.