# Uploading and downloading contact to Sharepoint or Onedrive

tl,dr: Don't write your own script - just use rclone, available from: https://rclone.org/

rclone:

  • is FOSS
  • supports numerous cloud services.
  • will work cross-platform with ease (pick your OS)
  • allows you to upload, download and sync
  • supports maintaining directory paths

# Quick steps

This is a good visual guide for setup: Connecting to OneDrive with RClone - Murray's Blog

# Copy (upload) files

A quick summary of the steps:

  1. Change directory to where rclone.exe is located, and run:
rclone config
  1. Select the option to make a new remote
  2. Create the config, by:
    1. Giving it a name,
    2. Selecting correct storage option (38 for OneDrive/SharePoint at time of writing)
    3. Accepting defaults for client_id, client_secret
    4. Select correct region for your tenant
    5. Accept defaults for tenant
    6. Do not edit advanced config
    7. Use the web browser to automatically authenticate with your remote, and complete the authentication and permission steps.
    8. Select the correct type of connection for what you are setting up (1 for OneDrive Personal or Business, etc). Options will be available to search for a OneDrive driveid or SharePoint site if needed.
    9. Select the drive you want to use (always select the one named OneDrive (business))
    10. Enter y, or press enter to save config
    11. Enter y, or press enter to keep the remote
    12. Enter q to quit
  3. Test the config by connecting to your new share, with this command:
.\rclone.exe ls RClone-Share-Name:"/path/to/destination/folder name/"
  1. Start uploading your content:
.\rclone.exe copy "E:\path\to\origin\folder name"  RClone-Share-Name:"/path/to/destination/folder name/" -P --metadata --check-first --inplace -i -v

Command breakdown:

Switch Purpose
-P View real-time transfer statistics
--metadata If set, preserve metadata when copying objects
--check-first Do all the checks before starting transfers
--inplace Download directly to destination file instead of atomic download to temp/rename
-i Enable interactive mode
-v Print lots more stuff (repeat for more)

Other command switches can be found at: https://rclone.org/commands/rclone_copy/#copy-options