github.com/10XDev/rclone@v1.52.3-0.20200626220027-16af9ab76b2a/docs/content/onedrive.md (about)

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