A cross-platform command line client for Microsoft OneDrive written in Java 7.
This application is currently in BETA - use with caution
(1) Download and extract the latest release.
(2) Authorise the application
An authorisation token must be created to grant the application secure access to OneDrive. Run the following command to generate the authorisation URL:
java -jar onedrive-java-client.jar --authorise
Open the URL in your browser, and wait for it to redirect you to a blank page. Copy and paste the address shown in your address bar into your keyfile (default file
(3) Start synchronising folders
java -jar onedrive-java-client.jar --direction UP --local . --remote MyTargetFolder/
(1) Grab the latest source code
git clone https://github.com/wooti/onedrive-java-client.git cd onedrive-java-client
(2) Build the application using Maven
mvn clean package -DskipTests
usage: onedrive-java-syncer -a,--authorise show authorisation url -c,--hash-compare always compare files by hash --direction <up|down> direction of synchronisation. -h,--help print this message -i,--ignore <ignore_file> ignore entry file -k,--keyfile <file> key file to use -L,--log-level <level (1-7)> controls the verbosity of logging --local <path> the local path --logfile <file> log to file -M,--max-size <size_in_KB> only process files smaller than <size> KB -n,--dry-run only do a dry run without making changes -r,--recursive recurse into directories --remote <path> the remote path on OneDrive -s,--split-after <size_in_MB> use multi-part upload for big files -t,--threads <count> number of threads to use -v,--version print the version information and exit -y,--tries <count> try each service request <count> times
The application currently supports one-way mirroring of data, so it will create, update and delete files as necessary to make the target side match the source side.
--direction UP- Mirrors a local folder to a remote OneDrive folder
--direction DOWN- Mirrors a remote OneDrive folder to a local folder
Note that the local and target folder must both exist for this to work.
Moving / Renaming Files
The client does not currently maintain a local record of changes, so renamed and moved files are detected as brand new files and uploaded. The old file will be deleted.
For files larger than 5MB (configurable with
--split-after), onedrive-java-client will split the upload into blocks of 5MB. This reduces the cost of a temporary network failure, as at most the last 5MB of any upload will need to be re-sent.
By default files are compared by looking at the size, created date and last modified date. For additional safety the
--hash-compare flag can be specified which forces a CRC32 hash check for each file.
--dry-run option can be used to test the synchronisation operation, this executes the operation without applying any changes.
The OneDrive API documentation can be found here
The following libraries have been used
- Google HTTP Client - HTTP REST Client
- Google GSON - JSON Parser
- Apache Commons CLI - Command line arguments parser
- Apache Log4j2 - Logging framework
- Apache HTTPComponents - Apache HTTP Client
The following key features are currently planned / under development:
- Full two-way synchronisation support (with use of a local state database)
- Support for OneDrive for Business
- Improvements to the
(C) 2017 Wouter Breukink