github.com/xhghs/rclone@v1.51.1-0.20200430155106-e186a28cced8/docs/content/onedrive.md (about) 1 --- 2 title: "Microsoft OneDrive" 3 description: "Rclone docs for Microsoft OneDrive" 4 date: "2015-10-14" 5 --- 6 7 <i class="fab fa-windows"></i> Microsoft OneDrive 8 ----------------------------------------- 9 10 Paths are specified as `remote:path` 11 12 Paths may be as deep as required, eg `remote:directory/subdirectory`. 13 14 The initial setup for OneDrive involves getting a token from 15 Microsoft which you need to do in your browser. `rclone config` walks 16 you through it. 17 18 Here is an example of how to make a remote called `remote`. First run: 19 20 rclone config 21 22 This will guide you through an interactive setup process: 23 24 ``` 25 e) Edit existing remote 26 n) New remote 27 d) Delete remote 28 r) Rename remote 29 c) Copy remote 30 s) Set configuration password 31 q) Quit config 32 e/n/d/r/c/s/q> n 33 name> remote 34 Type of storage to configure. 35 Enter a string value. Press Enter for the default (""). 36 Choose a number from below, or type in your own value 37 [snip] 38 XX / Microsoft OneDrive 39 \ "onedrive" 40 [snip] 41 Storage> onedrive 42 Microsoft App Client Id 43 Leave blank normally. 44 Enter a string value. Press Enter for the default (""). 45 client_id> 46 Microsoft App Client Secret 47 Leave blank normally. 48 Enter a string value. Press Enter for the default (""). 49 client_secret> 50 Edit advanced config? (y/n) 51 y) Yes 52 n) No 53 y/n> n 54 Remote config 55 Use auto config? 56 * Say Y if not sure 57 * Say N if you are working on a remote or headless machine 58 y) Yes 59 n) No 60 y/n> y 61 If your browser doesn't open automatically go to the following link: http://127.0.0.1:53682/auth 62 Log in and authorize rclone for access 63 Waiting for code... 64 Got code 65 Choose a number from below, or type in an existing value 66 1 / OneDrive Personal or Business 67 \ "onedrive" 68 2 / Sharepoint site 69 \ "sharepoint" 70 3 / Type in driveID 71 \ "driveid" 72 4 / Type in SiteID 73 \ "siteid" 74 5 / Search a Sharepoint site 75 \ "search" 76 Your choice> 1 77 Found 1 drives, please select the one you want to use: 78 0: OneDrive (business) id=b!Eqwertyuiopasdfghjklzxcvbnm-7mnbvcxzlkjhgfdsapoiuytrewqk 79 Chose drive to use:> 0 80 Found drive 'root' of type 'business', URL: https://org-my.sharepoint.com/personal/you/Documents 81 Is that okay? 82 y) Yes 83 n) No 84 y/n> y 85 -------------------- 86 [remote] 87 type = onedrive 88 token = {"access_token":"youraccesstoken","token_type":"Bearer","refresh_token":"yourrefreshtoken","expiry":"2018-08-26T22:39:52.486512262+08:00"} 89 drive_id = b!Eqwertyuiopasdfghjklzxcvbnm-7mnbvcxzlkjhgfdsapoiuytrewqk 90 drive_type = business 91 -------------------- 92 y) Yes this is OK 93 e) Edit this remote 94 d) Delete this remote 95 y/e/d> y 96 ``` 97 98 See the [remote setup docs](/remote_setup/) for how to set it up on a 99 machine with no Internet browser available. 100 101 Note that rclone runs a webserver on your local machine to collect the 102 token as returned from Microsoft. This only runs from the moment it 103 opens your browser to the moment you get back the verification 104 code. This is on `http://127.0.0.1:53682/` and this it may require 105 you to unblock it temporarily if you are running a host firewall. 106 107 Once configured you can then use `rclone` like this, 108 109 List directories in top level of your OneDrive 110 111 rclone lsd remote: 112 113 List all the files in your OneDrive 114 115 rclone ls remote: 116 117 To copy a local directory to an OneDrive directory called backup 118 119 rclone copy /home/source remote:backup 120 121 ### Getting your own Client ID and Key ### 122 123 You can use your own Client ID if the default (`client_id` left blank) 124 one doesn't work for you or you see lots of throttling. The default 125 Client ID and Key is shared by all rclone users when performing 126 requests. 127 128 If you are having problems with them (E.g., seeing a lot of throttling), you can get your own 129 Client ID and Key by following the steps below: 130 131 1. Open https://portal.azure.com/#blade/Microsoft_AAD_RegisteredApps/ApplicationsListBlade, then click `New registration`. 132 2. Enter a name for your app, choose account type `Any Azure AD directory - Multitenant`, select `Web` in `Redirect URI` Enter `http://localhost:53682/` and click Register. Copy and keep the `Application (client) ID` under the app name for later use. 133 3. Under `manage` select `Certificates & secrets`, click `New client secret`. Copy and keep that secret for later use. 134 4. Under `manage` select `API permissions`, click `Add a permission` and select `Microsoft Graph` then select `delegated permissions`. 135 5. Search and select the follwing permssions: `Files.Read`, `Files.ReadWrite`, `Files.Read.All`, `Files.ReadWrite.All`, `offline_access`, `User.Read`. Once selected click `Add permissions` at the bottom. 136 137 Now the application is complete. Run `rclone config` to create or edit a OneDrive remote. 138 Supply the app ID and password as Client ID and Secret, respectively. rclone will walk you through the remaining steps. 139 140 ### Modification time and hashes ### 141 142 OneDrive allows modification times to be set on objects accurate to 1 143 second. These will be used to detect whether objects need syncing or 144 not. 145 146 OneDrive personal supports SHA1 type hashes. OneDrive for business and 147 Sharepoint Server support 148 [QuickXorHash](https://docs.microsoft.com/en-us/onedrive/developer/code-snippets/quickxorhash). 149 150 For all types of OneDrive you can use the `--checksum` flag. 151 152 ### Restricted filename characters ### 153 154 In addition to the [default restricted characters set](/overview/#restricted-characters) 155 the following characters are also replaced: 156 157 | Character | Value | Replacement | 158 | --------- |:-----:|:-----------:| 159 | " | 0x22 | " | 160 | * | 0x2A | * | 161 | : | 0x3A | : | 162 | < | 0x3C | < | 163 | > | 0x3E | > | 164 | ? | 0x3F | ? | 165 | \ | 0x5C | \ | 166 | \| | 0x7C | | | 167 | # | 0x23 | # | 168 | % | 0x25 | % | 169 170 File names can also not end with the following characters. 171 These only get replaced if they are last character in the name: 172 173 | Character | Value | Replacement | 174 | --------- |:-----:|:-----------:| 175 | SP | 0x20 | ␠ | 176 | . | 0x2E | . | 177 178 File names can also not begin with the following characters. 179 These only get replaced if they are first character in the name: 180 181 | Character | Value | Replacement | 182 | --------- |:-----:|:-----------:| 183 | SP | 0x20 | ␠ | 184 | ~ | 0x7E | ~ | 185 186 Invalid UTF-8 bytes will also be [replaced](/overview/#invalid-utf8), 187 as they can't be used in JSON strings. 188 189 ### Deleting files ### 190 191 Any files you delete with rclone will end up in the trash. Microsoft 192 doesn't provide an API to permanently delete files, nor to empty the 193 trash, so you will have to do that with one of Microsoft's apps or via 194 the OneDrive website. 195 196 <!--- autogenerated options start - DO NOT EDIT, instead edit fs.RegInfo in backend/onedrive/onedrive.go then run make backenddocs --> 197 ### Standard Options 198 199 Here are the standard options specific to onedrive (Microsoft OneDrive). 200 201 #### --onedrive-client-id 202 203 Microsoft App Client Id 204 Leave blank normally. 205 206 - Config: client_id 207 - Env Var: RCLONE_ONEDRIVE_CLIENT_ID 208 - Type: string 209 - Default: "" 210 211 #### --onedrive-client-secret 212 213 Microsoft App Client Secret 214 Leave blank normally. 215 216 - Config: client_secret 217 - Env Var: RCLONE_ONEDRIVE_CLIENT_SECRET 218 - Type: string 219 - Default: "" 220 221 ### Advanced Options 222 223 Here are the advanced options specific to onedrive (Microsoft OneDrive). 224 225 #### --onedrive-chunk-size 226 227 Chunk size to upload files with - must be multiple of 320k (327,680 bytes). 228 229 Above this size files will be chunked - must be multiple of 320k (327,680 bytes). Note 230 that the chunks will be buffered into memory. 231 232 - Config: chunk_size 233 - Env Var: RCLONE_ONEDRIVE_CHUNK_SIZE 234 - Type: SizeSuffix 235 - Default: 10M 236 237 #### --onedrive-drive-id 238 239 The ID of the drive to use 240 241 - Config: drive_id 242 - Env Var: RCLONE_ONEDRIVE_DRIVE_ID 243 - Type: string 244 - Default: "" 245 246 #### --onedrive-drive-type 247 248 The type of the drive ( personal | business | documentLibrary ) 249 250 - Config: drive_type 251 - Env Var: RCLONE_ONEDRIVE_DRIVE_TYPE 252 - Type: string 253 - Default: "" 254 255 #### --onedrive-expose-onenote-files 256 257 Set to make OneNote files show up in directory listings. 258 259 By default rclone will hide OneNote files in directory listings because 260 operations like "Open" and "Update" won't work on them. But this 261 behaviour may also prevent you from deleting them. If you want to 262 delete OneNote files or otherwise want them to show up in directory 263 listing, set this option. 264 265 - Config: expose_onenote_files 266 - Env Var: RCLONE_ONEDRIVE_EXPOSE_ONENOTE_FILES 267 - Type: bool 268 - Default: false 269 270 #### --onedrive-encoding 271 272 This sets the encoding for the backend. 273 274 See: the [encoding section in the overview](/overview/#encoding) for more info. 275 276 - Config: encoding 277 - Env Var: RCLONE_ONEDRIVE_ENCODING 278 - Type: MultiEncoder 279 - Default: Slash,LtGt,DoubleQuote,Colon,Question,Asterisk,Pipe,Hash,Percent,BackSlash,Del,Ctl,LeftSpace,LeftTilde,RightSpace,RightPeriod,InvalidUtf8,Dot 280 281 <!--- autogenerated options stop --> 282 283 ### Limitations ### 284 285 #### Naming #### 286 287 Note that OneDrive is case insensitive so you can't have a 288 file called "Hello.doc" and one called "hello.doc". 289 290 There are quite a few characters that can't be in OneDrive file 291 names. These can't occur on Windows platforms, but on non-Windows 292 platforms they are common. Rclone will map these names to and from an 293 identical looking unicode equivalent. For example if a file has a `?` 294 in it will be mapped to `?` instead. 295 296 #### File sizes #### 297 298 The largest allowed file sizes are 15GB for OneDrive for Business and 35GB for OneDrive Personal (Updated 4 Jan 2019). 299 300 #### Path length #### 301 302 The entire path, including the file name, must contain fewer than 400 characters for OneDrive, OneDrive for Business and SharePoint Online. If you are encrypting file and folder names with rclone, you may want to pay attention to this limitation because the encrypted names are typically longer than the original ones. 303 304 #### Number of files #### 305 306 OneDrive seems to be OK with at least 50,000 files in a folder, but at 307 100,000 rclone will get errors listing the directory like `couldn’t 308 list files: UnknownError:`. See 309 [#2707](https://github.com/rclone/rclone/issues/2707) for more info. 310 311 An official document about the limitations for different types of OneDrive can be found [here](https://support.office.com/en-us/article/invalid-file-names-and-file-types-in-onedrive-onedrive-for-business-and-sharepoint-64883a5d-228e-48f5-b3d2-eb39e07630fa). 312 313 ### Versioning issue ### 314 315 Every change in OneDrive causes the service to create a new version. 316 This counts against a users quota. 317 For example changing the modification time of a file creates a second 318 version, so the file is using twice the space. 319 320 The `copy` is the only rclone command affected by this as we copy 321 the file and then afterwards set the modification time to match the 322 source file. 323 324 **Note**: Starting October 2018, users will no longer be able to disable versioning by default. This is because Microsoft has brought an [update](https://techcommunity.microsoft.com/t5/Microsoft-OneDrive-Blog/New-Updates-to-OneDrive-and-SharePoint-Team-Site-Versioning/ba-p/204390) to the mechanism. To change this new default setting, a PowerShell command is required to be run by a SharePoint admin. If you are an admin, you can run these commands in PowerShell to change that setting: 325 326 1. `Install-Module -Name Microsoft.Online.SharePoint.PowerShell` (in case you haven't installed this already) 327 1. `Import-Module Microsoft.Online.SharePoint.PowerShell -DisableNameChecking` 328 1. `Connect-SPOService -Url https://YOURSITE-admin.sharepoint.com -Credential YOU@YOURSITE.COM` (replacing `YOURSITE`, `YOU`, `YOURSITE.COM` with the actual values; this will prompt for your credentials) 329 1. `Set-SPOTenant -EnableMinimumVersionRequirement $False` 330 1. `Disconnect-SPOService` (to disconnect from the server) 331 332 *Below are the steps for normal users to disable versioning. If you don't see the "No Versioning" option, make sure the above requirements are met.* 333 334 User [Weropol](https://github.com/Weropol) has found a method to disable 335 versioning on OneDrive 336 337 1. Open the settings menu by clicking on the gear symbol at the top of the OneDrive Business page. 338 2. Click Site settings. 339 3. Once on the Site settings page, navigate to Site Administration > Site libraries and lists. 340 4. Click Customize "Documents". 341 5. Click General Settings > Versioning Settings. 342 6. Under Document Version History select the option No versioning. 343 Note: This will disable the creation of new file versions, but will not remove any previous versions. Your documents are safe. 344 7. Apply the changes by clicking OK. 345 8. Use rclone to upload or modify files. (I also use the --no-update-modtime flag) 346 9. Restore the versioning settings after using rclone. (Optional) 347 348 ### Troubleshooting ### 349 350 #### Unexpected file size/hash differences on Sharepoint #### 351 352 It is a 353 [known](https://github.com/OneDrive/onedrive-api-docs/issues/935#issuecomment-441741631) 354 issue that Sharepoint (not OneDrive or OneDrive for Business) silently modifies 355 uploaded files, mainly Office files (.docx, .xlsx, etc.), causing file size and 356 hash checks to fail. To use rclone with such affected files on Sharepoint, you 357 may disable these checks with the following command line arguments: 358 359 ``` 360 --ignore-checksum --ignore-size 361 ``` 362 363 #### Replacing/deleting existing files on Sharepoint gets "item not found" #### 364 365 It is a [known](https://github.com/OneDrive/onedrive-api-docs/issues/1068) issue 366 that Sharepoint (not OneDrive or OneDrive for Business) may return "item not 367 found" errors when users try to replace or delete uploaded files; this seems to 368 mainly affect Office files (.docx, .xlsx, etc.). As a workaround, you may use 369 the `--backup-dir <BACKUP_DIR>` command line argument so rclone moves the 370 files to be replaced/deleted into a given backup directory (instead of directly 371 replacing/deleting them). For example, to instruct rclone to move the files into 372 the directory `rclone-backup-dir` on backend `mysharepoint`, you may use: 373 374 ``` 375 --backup-dir mysharepoint:rclone-backup-dir 376 ``` 377 378 #### access\_denied (AADSTS65005) #### 379 380 ``` 381 Error: access_denied 382 Code: AADSTS65005 383 Description: Using application 'rclone' is currently not supported for your organization [YOUR_ORGANIZATION] because it is in an unmanaged state. An administrator needs to claim ownership of the company by DNS validation of [YOUR_ORGANIZATION] before the application rclone can be provisioned. 384 ``` 385 386 This means that rclone can't use the OneDrive for Business API with your account. You can't do much about it, maybe write an email to your admins. 387 388 However, there are other ways to interact with your OneDrive account. Have a look at the webdav backend: https://rclone.org/webdav/#sharepoint 389 390 #### invalid\_grant (AADSTS50076) #### 391 392 ``` 393 Error: invalid_grant 394 Code: AADSTS50076 395 Description: Due to a configuration change made by your administrator, or because you moved to a new location, you must use multi-factor authentication to access '...'. 396 ``` 397 398 If you see the error above after enabling multi-factor authentication for your account, you can fix it by refreshing your OAuth refresh token. To do that, run `rclone config`, and choose to edit your OneDrive backend. Then, you don't need to actually make any changes until you reach this question: `Already have a token - refresh?`. For this question, answer `y` and go through the process to refresh your token, just like the first time the backend is configured. After this, rclone should work again for this backend.