Rclone配置onedrive和google drive上传教程

, Read in about 8 min

Posted by Ryen on Sunday, January 17, 2021
With final update in December 26,2023

本文总阅读量

需求:Linux服务器上下载了好多资源。但是Linux没有onedrivegoogle drive的客户端。

那么如何把vps上的文件传到onedrive呢。

这里我们可以用rclone这个工具。

先安装****rclone

第一步:我们先在windows上配置一下

下载windows对应位数的压缩包,网址:https://rclone.org/downloads/

先解压到D:\rclone

管理员命令提示符(cmd)输入下面的命令,回车

cd /d d:\rclone\rclone
rclone authorize "onedrive"

会自动打开浏览器让你登录你的onedrive账户

点击授权后浏览器显示如图

回到cmd,发现多了一大串字符。复制花括号里的所有字符,新建一个文档保存,一会要用。

第二步:开始配置Linux

打开你的SHH工具连接vps,我的是ubuntu系统,输入:

apt-get update
apt-get install -y unzip fuse

然后输入:

wget https://downloads.rclone.org/rclone-current-linux-amd64.zip
unzip rclone-current-linux-amd64.zip
chmod 0777 ./rclone-*/rclone
cp ./rclone-*/rclone /usr/bin/
rm -rf ./rclone-*

然后输入:

rclone config

即可调出配置信息

第三步:新建

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> 

输入n
显示如下
name>
这里我们起个名字

第四步:出现一堆网盘序号

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 Providers including AWS, Alibaba, Ceph, Digital Ocean, Dreamhost, IBM COS, Minio, and Tencent COS
   \ "s3"
 5 / Backblaze B2
   \ "b2"
 6 / Box
   \ "box"
 7 / Cache a remote
   \ "cache"
 8 / Citrix Sharefile
   \ "sharefile"
 9 / Compress a remote
   \ "compress"
10 / Dropbox
   \ "dropbox"
11 / Encrypt/Decrypt a remote
   \ "crypt"
12 / Enterprise File Fabric
   \ "filefabric"
13 / FTP Connection
   \ "ftp"
14 / Google Cloud Storage (this is not Google Drive)
   \ "google cloud storage"
15 / Google Drive
   \ "drive"
16 / Google Photos
   \ "google photos"
17 / Hadoop distributed file system
   \ "hdfs"
18 / Hubic
   \ "hubic"
19 / In memory object storage system.
   \ "memory"
20 / Jottacloud
   \ "jottacloud"
21 / Koofr
   \ "koofr"
22 / Local Disk
   \ "local"
23 / Mail.ru Cloud
   \ "mailru"
24 / Mega
   \ "mega"
25 / Microsoft Azure Blob Storage
   \ "azureblob"
26 / Microsoft OneDrive
   \ "onedrive"
27 / OpenDrive
   \ "opendrive"
28 / OpenStack Swift (Rackspace Cloud Files, Memset Memstore, OVH)
   \ "swift"
29 / Pcloud
   \ "pcloud"
30 / Put.io
   \ "putio"
31 / QingCloud Object Storage
   \ "qingstor"
32 / SSH/SFTP Connection
   \ "sftp"
33 / Sugarsync
   \ "sugarsync"
34 / Tardigrade Decentralized Cloud Storage
   \ "tardigrade"
35 / Transparently chunk/split large files
   \ "chunker"
36 / Union merges the contents of several upstream fs
   \ "union"
37 / Webdav
   \ "webdav"
38 / Yandex Disk
   \ "yandex"
39 / Zoho
   \ "zoho"
40 / http Connection
   \ "http"
41 / premiumize.me
   \ "premiumizeme"
42 / seafile
   \ "seafile"
Storage> 26
** See help for onedrive backend at: https://rclone.org/onedrive/ **


找到对应的序号,我这里onedrive是26号。
输入26回车
OAuth Client Id
Leave blank normally.
Enter a string value. Press Enter for the default ("").
client_id> 
OAuth Client Secret
Leave blank normally.
Enter a string value. Press Enter for the default ("").
client_secret> 

# id与 secret 直接回车

第五步: 选择云盘地区,这里不清楚直接回车

Choose national cloud region for OneDrive.
Enter a string value. Press Enter for the default ("global").
Choose a number from below, or type in your own value
 1 / Microsoft Cloud Global
   \ "global"
 2 / Microsoft Cloud for US Government
   \ "us"
 3 / Microsoft Cloud Germany
   \ "de"
 4 / Azure and Office 365 operated by 21Vianet in China
   \ "cn"
region> 

第六步: 修改高级配置,默认NO,回车

Edit advanced config? (y/n)
y) Yes
n) No (default)
y/n> 

第七步: 如果是远程服务器打开浏览器查看配置(第一步)选yes,本地电脑选no

 * Say Y if not sure
 * Say N if you are working on a remote or headless machine
y) Yes (default)
n) No
y/n>  No

第八步: 输入第一步获取的配置

For this to work, you will need rclone available on a machine that has
a web browser available.

For more help and alternate methods see: https://rclone.org/remote_setup/

Execute the following on the machine with the web browser (same rclone
version recommended):

        rclone authorize "onedrive"

Then paste the result below:
result> 



#这里我们输入刚才复制的一大堆字符串
Choose a number from below, or type in an existing value
 1 / OneDrive Personal or Business
   \ "onedrive"
 2 / Root Sharepoint site
   \ "sharepoint"
 3 / Sharepoint site name or URL (e.g. mysite or https://contoso.sharepoint.com/sites/mysite)
   \ "url"
 4 / Search for a Sharepoint site
   \ "search"
 5 / Type in driveID (advanced)
   \ "driveid"
 6 / Type in SiteID (advanced)
   \ "siteid"
 7 / Sharepoint server-relative path (advanced, e.g. /teams/hr)
   \ "path"
Your choice> 

#这里输入1
Found 1 drives, please select the one you want to use:
0: OneDrive (business) id=b!5aaxzEKnQ0moUdSJN5FFiz18jOg3bKJDpnlLne7FeEjh0fnzsP3TSIpazFa4zHn9
Chose drive to use:>

这里显示出来了网盘序号,输入0

第九步:接下来

Found drive 'root' of type 'business', URL: https://ememe-my.sharepoint.com/personal/admin_ememe_onmicrosoft_com/Documents
Is that okay?
y) Yes (default)
n) No
y/n> 

配置好了。输入y

drive_id = b!5aaxzEKnQ0moUdSJN5FFiz18jOg3bKJDpnlLne7FeEjh0fnzsP3TSIpazFa4zHn9
drive_type = business
--------------------
y) Yes this is OK (default)
e) Edit this remote
d) Delete this remote
y/e/d

到这里我就就已经配置完成,输入y
然后就没事了。输入q退出rclone就行

第十步:别忘了还需要安装个screen

apt-get install -y screen    //这是debian系

centos系安装screen需要使用yum install screen

上传命令

rclone move source:path dest:path    //别急看完下面的

screen rclone move /root/download onedrive1:/upload --transfers 32 -P    //完整的命令

参数详解:

source:path是本地目录,dest:path是云端目录

其中dest是网盘名称,就你刚才随便取的那个path就是目录

你可以指定上传到哪一个文件夹

比如说,

我要把本地的/root/download目录下所有的文件移动到onedrive里面的/upload文件夹里面

命令应该是rclone move /root/download onedrive1:/upload

但是这样上传的话,他一直在前台上传,占用你的ssh。
想让他变成后台,在前面加上screen

命令就是:screen rclone move /root/download onedrive1:/upload

这样你就可以关掉ssh,他就可以在后台上传

如果文件目录比较复杂,而且文件数量庞大
可以提高线程,他默认是4线程,测试后发现100M带宽32线程效果最好。(根据你的vps而定线程。)

可以在后面再加一个参数 -P(大写)显示上传详情

screen rclone move /root/download onedrive1:/upload –transfers 32 -P

screen

等你想看看传完了没有的时候,
screen -ls就可以看到后台screen进程。

配置google drive盘

1.配置

google drive盘有区分

个人盘团队盘

这里我们先配置团队盘,个人盘也同理。

  1. 输入 rclone config
  2. 输入 n
  3. 提示如下:
  4. 给本次配置的网盘起个名字
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> n
name> 
这网盘起个名字
12 / Google Cloud Storage (this is not Google Drive)
   \ "google cloud storage"
13 / Google Drive
   \ "drive"
14 / Google Photos
   \ "google photos"
   选择13
** See help for drive backend at: https://rclone.org/drive/ **

Google Application Client Id
Setting your own is recommended.
See https://rclone.org/drive/#making-your-own-client-id for how to create your own.
If you leave this blank, it will use an internal key which is low performance.
Enter a string value. Press Enter for the default ("").
client_id> 
空着就行,回车

翻译:

建议您设置自己的Google Application Client ID。有关如何创建自己的示例,请参见https://rclone.org/drive/#making-your-own-client-id。如果将此空白留空,它将使用性能低下的内部密钥。输入一个字符串值。按Enter作为默认值(“”)。

Google Application Client Secret
Setting your own is recommended.
Enter a string value. Press Enter for the default ("").
client_secret> 
空着,就行

翻译:

建议设置您自己的Google Application Client Secret。输入一个字符串值。按Enter作为默认值(“”)。

Scope that rclone should use when requesting access from drive.
Enter a string value. Press Enter for the default ("").
Choose a number from below, or type in your own value
 1 / Full access all files, excluding Application Data Folder.
   \ "drive"
 2 / Read-only access to file metadata and file contents.
   \ "drive.readonly"
   / Access to files created by rclone only.
 3 | These are visible in the drive website.
   | File authorization is revoked when the user deauthorizes the app.
   \ "drive.file"
   / Allows read and write access to the Application Data folder.
 4 | This is not visible in the drive website.
   \ "drive.appfolder"
   / Allows read-only access to file metadata but
 5 | does not allow any access to read or download file content.
   \ "drive.metadata.readonly"
scope> 
输入1

大概的机翻:

rclone从驱动器请求访问时应使用的范围。输入一个字符串值。按Enter作为默认值(“”)。

从下面选择一个数字,或键入您自己的值

1 /完全访问所有文件,但不包括应用程序数据文件夹。

\“ drive”

2 /对文件元数据和文件内容的只读访问。

\“ drive.readonly” /仅访问由rclone创建的文件。

3 |这些在驱动器网站上可见。 |当用户取消对应用程序的授权时,文件授权将被吊销。 \“ drive.file” /允许对“应用程序数据”文件夹进行读写访问。

4 |这在驱动器网站上不可见。 \“ drive.appfolder” /允许只读访问文件元数据,但

5 |不允许任何访问来读取或下载文件内容。 \“

ID of the root folder
Leave blank normally.

Fill in to access "Computers" folders (see docs), or for rclone to use
a non root folder as its starting point.

Note that if this is blank, the first time rclone runs it will fill it
in with the ID of the root folder.

Enter a string value. Press Enter for the default ("").
root_folder_id> 
空着,回车

机翻:

根文件夹的ID通常保留空白。填写以访问“计算机”文件夹(请参阅文档),或让rclone使用非根文件夹作为起点。请注意,如果为空,则第一次运行rclone时,它将使用根文件夹的ID进行填充。输入一个字符串值。按Enter作为默认值(“”)。

Service Account Credentials JSON file path 
Leave blank normally.
Needed only if you want use SA instead of interactive login.
Enter a string value. Press Enter for the default ("").
service_account_file> 
空着,回车

机翻:

服务帐户凭据JSON文件路径通常留空。仅当您要使用SA而不是交互式登录时才需要。输入一个字符串值。按Enter作为默认值

Service Account Credentials JSON file path 
Leave blank normally.
Needed only if you want use SA instead of interactive login.
Enter a string value. Press Enter for the default ("").
service_account_file> 
Edit advanced config? (y/n)
y) Yes
n) No (default)
y/n> 
空着,回车

机翻**:**

服务帐户凭据JSON文件路径通常留空。仅当您要使用SA而不是交互式登录时才需要。输入一个字符串值。按Enter作为默认值(“”)。 service_account_file>编辑高级配置?

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> 
   输入n

机翻:

远程配置使用自动配置? *如果不确定,则说Y *如果在远程或无头机器上工作,请说N

Please go to the following link:

https://accounts.google.com/o/oauth2/auth?access_type=offline&client_id20264815644.apps.googleusercontent.com&redirect_uri=urn%3Aietf%3Awgoauth%3A2.0%3Aoob&response_type=code&scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fdrive&state=kXGnW8AtxDZinUY7auTP9w

Log in and authorize rclone for access
Enter verification code> 
把提示的这个连接放到浏览器打开

登录你的账户

授权允许,出现这个代码,复制粘贴到SSH工具,回车

“Configure this as a team drive?
y) Yes
n) No (default)
y/n>
注意注意注意,配置个人盘就输入n,配置团队盘输入y
<pre><code class=""><br />**机翻:**
将此配置为团队盘吗?
“`shell
Fetching team drive list…
Choose a number from below, or type in your own value
1 / admin-lifan-ooo-fjhechuan
\ “0ABiUAIea2iibk9PVA”
2 / chyon
\ “0AP6QmoAnW_Qbk9PVA”
3 / hechuan-MoeClub
\ “0APYqQlQeZnpwU9PVA”
4 / hechuan
\ “0AG97tphYvnZ_U9PVA”
5 / hy-fjhechuan
\ “0ANzkcvxKCBWak9PVA”
Enter a Team Drive ID>
#列出了我账户下所有的团队盘。你想配置哪个就输入对应的序号。
#我想用5号,就输入5
[google_hy]
type = drive
scope = drive
token = {"access_token":"ya29.Il-9B-x15fy1sfTMSML-MkqVgTq2W0W_VVqluwoWXuioeglrF-LnjinhMGDyqa0HDk0SYTvXkAMZviYx2yM40AnMl4IK-3QhAf1FE54X2hVOiIuDpiRsU3oClksw","token_type":"Bearer","refresh_token":"1//03ztJYkqbqDnuCgYIARAAGAMSNwF-L9IrKCRqVpsgKMqWSa0an_uMblaHiJS-FPCB9T6lGj2taVQ0U7og5m3z1FOuC-UlNDJL204","expiry":"2020-02-07T14:13:26.261934522Z"}

team_drive = 0ANzkcvxKCBWaUk9PVA
--------------------

y) Yes this is OK (default)
e) Edit this remote
d) Delete this remote
y/e/d> 
到这里就完成团队盘的配置了。

2.上传

上传之前别忘了

还需要安装个screen

apt-get install -y screen

上传命令

screen rclone move /1/aria2/ onedrive_rive:/upload --transfers 32 -P

测试一下上传。我把服务器本地的**/1/2目录里面的文件复制到谷歌云的upload**目录里。

开启12线程,显示上传详情,

命令就是:

screen rclone copy /1/2/ google_hy_fjhechuan:/upload --transfers 12 -P

「真诚赞赏,手留余香」

Ryen's Blog

真诚赞赏,手留余香

使用微信扫描二维码完成支付