利用修改版rclone来实现挂载磁盘到本地并上传下载世纪互联版onedrive

准备工作

在近期看到了很多修改版rclone的帖子,并且在github看到这个世纪互联版的rclone补丁:

https://gist.github.com/ShadeShady/81b6fecca82c289e8e5ae0637918e7e6

下面来介绍如何来使用修改版的rclone,首先说明,世纪互联版office365并不像国际版存在一个公用的参数,所以每个全局都需要自己创建Azure API使用,需要你的全局管理员参与并且授权。而且只要你的全局管理员创建了一个相应的ID,那么这个全局下所有子账户都可以使用这个ID。

首先打开并且登陆世纪互联版AAD: https://portal.azure.cn/#blade/Microsoft_AAD_IAM/ActiveDirectoryMenuBlade/Overview

img

点击应用注册,然后新注册

img

名字可以随意填写,我这里填写rclone

img

重定向URI,一定要填写 http://localhost,否则授权会一直提示uri错误

img

点击注册,然后记录下你的Client ID

img

然后选择证书和密码,创建密钥

img

记录下值,这就是rclone需要的密钥

img

然后选择API权限,添加权限

img

选择Microsoft Graph,不知道为什么我的界面错位了

img

选择应用程序权限

img

在下方Files里选择 Files.Read.All、Files.ReadWrite.All

img

回到界面会发现该权限处于未授权状态,我们需要全局管理员点击代表XXXX授予

img

稍等一会即可收到api授予同意的字样

img

至此AAD配置结束,可以去rclone直接配置了,注意应用ID和密钥需要记住,这个是对全局下所有子帐号皆可生效的。

配置Rclone

安装好这几个软件后,开始配置Rclone。

  1. 首先修改windows系统的环境变量,将rclone的路径添加到path中:
    在桌面上右键点击此电脑标志,然后点击属性->高级系统设置->环境变量->系统变量->Path

在这里插入图片描述
添加rclone文件夹的路径到path中,我电脑上rclone放置的路径在D:\Program Files\rclone-v1.51.0-windows-amd64
在这里插入图片描述2. 修改好环境变量之后,打开windows powershell,配置rclone.config。

按键盘上的win+x,然后按a键,即可调出windows powershell

输入rclone --version,可查看rclone是否成功安装。

Windows PowerShell
版权所有 (C) Microsoft Corporation。保留所有权利。

尝试新的跨平台 PowerShell https://aka.ms/pscore6

PS C:\Windows\system32> rclone --version
rclone v1.51.0
- os/arch: windows/amd64
- go version: go1.13.7
123456789

查看成功安装rclone后,输入rclone config,配置要加载的onedrive信息,按照下面的步骤依次进行下去。

PS C:\Windows\system32> rclone config  (步骤1. 输入rclone config)
2020/04/25 13:29:37 NOTICE: Config file "C:\\Users\\dell\\.config\\rclone\\rclone.conf" not found - using defaults
No remotes found - make a new one
n) New remote
s) Set configuration password
q) Quit config
n/s/q> n  (步骤2. 输入n,表示新建配置)
name> onedrive  (步骤3. 命名为"onedrive",也可取其他的名字,但要与下面所使用的名字保持一致)
Type of storage to configure.
Enter a string value. Press Enter for the default ("").
Choose a number from below, or type in your own value
 1 / 1Fichier
   \ "fichier"
 2 / Alias for an existing remote
   \ "alias"
 3 / Amazon Drive
   \ "amazon cloud drive"
 4 / Amazon S3 Compliant Storage Provider (AWS, Alibaba, Ceph, Digital Ocean, Dreamhost, IBM COS, Minio, etc)
   \ "s3"
 5 / Backblaze B2
   \ "b2"
 6 / Box
   \ "box"
 7 / Cache a remote
   \ "cache"
 8 / Citrix Sharefile
   \ "sharefile"
 9 / Dropbox
   \ "dropbox"
10 / Encrypt/Decrypt a remote
   \ "crypt"
11 / FTP Connection
   \ "ftp"
12 / Google Cloud Storage (this is not Google Drive)
   \ "google cloud storage"
13 / Google Drive
   \ "drive"
14 / Google Photos
   \ "google photos"
15 / Hubic
   \ "hubic"
16 / In memory object storage system.
   \ "memory"
17 / JottaCloud
   \ "jottacloud"
18 / Koofr
   \ "koofr"
19 / Local Disk
   \ "local"
20 / Mail.ru Cloud
   \ "mailru"
21 / Mega
   \ "mega"
22 / Microsoft Azure Blob Storage
   \ "azureblob"
23 / Microsoft OneDrive
   \ "onedrive"
24 / OpenDrive
   \ "opendrive"
25 / Openstack Swift (Rackspace Cloud Files, Memset Memstore, OVH)
   \ "swift"
26 / Pcloud
   \ "pcloud"
27 / Put.io
   \ "putio"
28 / QingCloud Object Storage
   \ "qingstor"
29 / SSH/SFTP Connection
   \ "sftp"
30 / Sugarsync
   \ "sugarsync"
31 / Transparently chunk/split large files
   \ "chunker"
32 / Union merges the contents of several remotes
   \ "union"
33 / Webdav
   \ "webdav"
34 / Yandex Disk
   \ "yandex"
35 / http Connection
   \ "http"
36 / premiumize.me
Storage> 23  (步骤4. 输入数字23,因为Microsoft OneDrive对应的类型是23)
** See help for onedrive backend at: https://rclone.org/onedrive/ **

Microsoft App Client Id
Leave blank normally.
Enter a string value. Press Enter for the default ("").
client_id>  (步骤5. 按enter键跳过)
Microsoft App Client Secret
Leave blank normally.
Enter a string value. Press Enter for the default ("").
client_secret>  (步骤6. 按enter键跳过)
Edit advanced config? (y/n)
y) Yes
n) No (default)
y/n> n  (步骤7. 输入n,采用默认设置)
Remote config
Use auto config?
 * Say Y if not sure
 * Say N if you are working on a remote or headless machine
y) Yes (default)
n) No
y/n> y (步骤8. 输入y,采用默认设置)
If your browser doesn't open automatically go to the following link: http://127.0.0.1:53682/auth?state=lcvcDmCLf1ugmaCzlEtMSA
Log in and authorize rclone for access
Waiting for code...
----------------------------------
(步骤8执行后会跳转到Microsoft OneDrive账号登录界面和授权界面,登录后在授权请求界面点击“是”)
-----------------------------------
Got code
Choose a number from below, or type in an existing value
 1 / OneDrive Personal or Business
   \ "onedrive"
 2 / Root Sharepoint site
   \ "sharepoint"
 3 / Type in driveID
   \ "driveid"
 4 / Type in SiteID
   \ "siteid"
 5 / Search a Sharepoint site
   \ "search"
Your choice> 1  (步骤9. 输入1,数字1对应OneDrive Personal or Business)
Found 1 drives, please select the one you want to use:
0:  (personal) id=cdffcd6a2a3dc176
Chose drive to use:> 0 (步骤10. 输入0,数字0对应OneDrive个人版)
Found drive 'root' of type 'personal', URL: https://onedrive.live.com/?cid=cdffcd6a2a3dc176
Is that okay?
y) Yes (default)
n) No
y/n> y  0 (步骤11. 输入y,采用默认设置)
--------------------
[onedrive]
type = onedrive
token = {"access_token":"(隐私信息省略)*************************************************************************************
drive_id = (隐私信息省略)***************
drive_type = personal
--------------------
y) Yes this is OK (default)
e) Edit this remote
d) Delete this remote
y/e/d> y  (步骤12. 输入y)
Current remotes:

Name                 Type
====                 ====
onedrive             onedrive

e) Edit existing remote
n) New remote
d) Delete remote
r) Rename remote
c) Copy remote
s) Set configuration password
q) Quit config
e/n/d/r/c/s/q> q  (步骤13. 输入q,退出)
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156

完成rclone配置后,挂载onedrive磁盘。
在git中输入如下命令并执行(注意,末尾的&很重要,不加&的话退出git则挂载就失效了):

rclone mount onedrive:/ E: --cache-dir D:\Onedrive --vfs-cache-mode writes &

到这一步,就可以在电脑上看到多出一个onedrive(E)磁盘。

但还没有结束,还需要解决电脑重启后挂载失效的问题。

开机自动挂载

采用开机自动挂载的方式,可有效解决电脑重启后onedrive磁盘消息的问题,省去重新手动挂载的麻烦。

新建两个文件,分别为rclone.bat和rclone.vbs

1.rclone.bat中写入上述挂载命令:

rclone mount onedrive:/ E: --cache-dir D:\Onedrive --vfs-cache-mode writes &

2.rclone.vbs设置开机自动调用cmd运行rclone.bat文件并退出cmd,写入如下代码:

CreateObject("WScript.Shell").Run "cmd /c D:/rclone.bat",0

将rclone.bat文件放到D盘(或其他的盘)目录下,我放在了D盘,所以在rclone.vbs中该文件的路径就是D:/rclone.bat

将rclone.vbs文件放到windows系统启动项目录下,在文件夹的路径框中输入
%USERPROFILE%\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup
即可进入启动项目录
在这里插入图片描述
至此,onedrive磁盘的挂载完成,且电脑下次开机时onedrive磁盘也不会消失。

转载自:

https://peachcat.org/archives/996
https://blog.csdn.net/LB_AUTO/article/details/105751277
tag(s): VPS
show comments · back · home
Edit with markdown