Skip to content

Multiplatform Command Line Interface for OneDrive

License

Notifications You must be signed in to change notification settings

incognito1234/onedrive-client

Repository files navigation

OneDrive Client Program

ODC is a command line tool to interact with a Microsoft OneDrive Personal Storage.

Available features

The following commands are available:

init              Init connexion
put               Upload a file
mput              Upload a complete folder
whoami            Get information about connected user
ls                List a folder content
shell             Interactive shell
get               Download a file
mget              Download a complete folder
stat              Get info from object
share             Share a file or a folder
mv                Move a file or a folder
rm                Remove a file or a folder
mkdir             Make a folder

odc.py with no argument launchs the interactive shell. On linux platform, it includes a completion feature which recognizes remote files and folders.

put/get commands include the uploading/downloading of large file with a retry mechanism in case a chunk is not correctly uploaded/downloaded.

A progress bar is optionnally available for downloading and uploading large file if the tqdm package is installed.

mget and get commands include a server throttling detection mechanism: if a throttling message is received, a timer is triggered until the server becomes available. In the case you plan to download large file or folder, it is recommended to install the tqdm package so that you can see the remaining time which may be significantly long (more than one hour).

Parameters of each command are described in help output

$ odc.py <command> -h

ODC in action

ScreenCast ODC

The screencast above demonstrates the following features:

  • Uploading of complete folder
  • Browsing OneDrive from the shell
  • Autocompletion of folder and file name
  • File removal from the shell
  • Detection of external changes by shell
  • Large file upload

Requisites

ODC has been tested with the following environment

  • python 3.8/python 3.9/python 3.10
  • Personal Microsoft account

Progress bar can be enabled when a large file or a complete folder is uploaded or downloaded. This feature needs tqdm python module. Differential uploading and downloading (mput and mget comands) are available if aquickxorhash command is available in PATH variable or if quickxorhash python module is installed.

Installation

On Azure portal

  • Register an application with the following properties

    Supported account types      Personal Microsoft accounts only
    Platform                     Web
    Redirect URI                 https://localhost:8000/auth/redirect
    
  • Create a secret assigned to this application

Tip to register an application on azure portal Jul 7 2024 process portal.azure.comMicrosoft Entra IDApp Registrations

On client computer

  • Create python environment and retrieve the code

    $ python3 -m venv envodc
    $ cd envodc
    $ git clone https://github.com/incognito1234/onedrive-client.git odc
    $ cd odc
    
  • Prepare python environment and install required packages

    $ . ../bin/activate
    $ pip -r requirements.txt
    
  • If you want to have progress bar during upload or downloading, install tqdm package

    $ pip install tqdm
    
  • On Windows platform, import the package pyreadline3

    $ pip install pyreadline3
    
  • Configure connexion to OneDrive

    • Copy oauth_settings.yml.sample in oauth_settings.yml

    • Copy/Paste Application ID and Secret Value of azure application in the relevant parts of oauth_settings.yml file

    • Initiate connexion

      $ ./odc.py init
      ... Copy/Paste provided URL in a browser
      ... Copy/Paste URL of the browser in the console
      
  • Optional: create a shortcut to launch ODC

      $ cat << EOF > /usr/local/sbin/odc
      #!/bin/sh
    
      <venv_folder>/bin/python <venv_folder>/odc/odc.py $@
      EOF
    
  • It is now possible to use ODC

    $ cd <venv_folder>/odc
    $ ./odc.py <args>
    

    or the shortcut has been created

    $ odc <args>
    

Changelog

Only main changes are listed here

Version 1.3

  • Improve error management during download
  • Add exclusion list as an option of mget command
  • Consider drive object which are not file or folder (could be a Notebook)
  • Use quickxorhash module if available (Thanks wienand)
  • Add max_retrieved_children in ls command to list folders with more than 200 children

Version 1.2

  • Consider error when downloading file with re-try mechanisms
  • Manage server throttling during download
  • Add progression bar (with tqdm package) during downloading
  • Add -l option for ls command

Version 1.1

  • Detect external changes when shell runs
  • Shell enhancement: Add put command
  • Shell enhancement: Add mkdir command
  • Shell enhancement: Add recursive option to folder listing
  • Shell enhancement: Allow multiple paths with ls command
  • Various bug fixes

Version 1.0

  • Initial version