Download files to a headless Linux system
The utility rclone can receive files from OneDrive on Linux (and other Unix-like) systems.
Establishing a shared folder between the sender and the recipient(s) will require all parties to do some one-off, interactive setup using a web browser.
Once sharing configuration is in place then files can be sent or received using command-line-driven or scripted workflows similar to those using `wget` or `curl` operating on OxFile URLs.
Rclone will need to be set up to communicate with OneDrive in following the configuration instructions. Obtaining an authentication token involves running a web browser and performing an MFA login.
If you are unable to run a graphical web browser on the target Linux machine then the remote setup instructions detail several ways that you can configure the remote machine in conjunction with a desktop or laptop (which can run a web browser).
In practice it is often simplest to configure by copying the config file.
Establishing the shared folder
The person sharing the files should follow the instructions for sharing a folder from their OneDrive using the OneDrive web interface, creating a suitably named folder to hold the file or files to be shared if one does not already exist. The sharing must be at the folder (rather than individual file) level so that the intended recipient(s) can create the required shortcuts in their personal OneDrive. The person sharing the folder has the option of granting Edit permission or not, depending on whether they just want to distribute files or to have the option to receive files from others in the same shared folder.
The person(s) receiving the sharing link should open it in a browser and click on the "Add shortcut to My files" link.
Everyone concerned should then have the same folder visible in their personal OneDrive, which can then be used for file transfers.
Once a suitable rclone configuration is set up on the remote machine then extensive rclone command set can be used to send/receive/list/synchronise and otherwise manipulate files and folders in the shared area.
Here are a few example commands, to get you started, given an rclone configuration where the remote is called remote and the previously established shared folder called transfers.
- Recursively list all the files in the transfers share, with file sizes: rclone ls remote:transfers
- Copy the entire contents of the shared folder to a local directory called dir: rclone copy remote:transfers dir
- Synchronise the local directory dir from the shared folder (including deleting from the local directory anything not present in the shared folder): rclone sync remote:transfers dir
- Copy a specific file from the transfers share to a local directory: rclone copy remote:transfers/name-of-file dir
resulting in a file dir/name-of-file.
- Copy a specific file, possibly renaming it in the process: rclone copyto remote:transfers/name-of-file new-name-of-file
resulting in a file named new-name-of-file in the current directory. The distinction between copy and copyto is that the target of a copy is always a directory; if the target directory does not already exist then it will be created.
- Feed the contents of a remote file or files into a Unix command: rclone cat remote:transfers/wordlist.txt | sort -u
If the user has Can Edit permission on the shared folder it is possible to use rclone to upload files as well as downloading them. Be aware, however, that writes to OneDrive via the API that rclone uses can be quite slow and subject to throttling by Microsoft: uploaders of large files or folder structures may find they are better served by the OneDrive web interface.