命令列使用 Google Drive

方案 1:使用 GDrive

https://github.com/marufshidiq/gdrive-cli-builder

方案 2:使用 rclone

apt-get -y install rclone

rclone config

操作記錄

root@80tm:~# rclone config
2020/04/10 02:03:40 NOTICE: Config file “/root/.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
name> googlepan1 #給項目起一個名字
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
\ “premiumizeme”
Storage> 13 #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 Secret
Setting your own is recommended.
Enter a string value. Press Enter for the default (“”).
client_secret> #直接回車
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 #完全的存取權限
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>
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> 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> n #不需要自動配置
Please go to the following link: https://accounts.google.com/o/oauth2/auth?access_type=offline&client_id=202264815644.apps.googleusercontent.com&redirect_uri=urn%3Aietf%3Awg%3Aoauth%3A2.0%3Aoob&response_type=code&scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fdrive&state=sK4NOjkW4PvvlACA2FmRlg
Log in and authorize rclone for access
Enter verification code> 4/ygGcD一長串數字 #複製上面的穀歌連結到流覽器位址打開授權獲取授權碼填寫到這裡
Configure this as a team drive?
y) Yes
n) No (default)
y/n> y #選擇穀歌團隊盤
Fetching team drive list…
Choose a number from below, or type in your own value
1 / drive2
\ “0ACwUIdUjXa-sdafsd”
2 / drive3
\ “0AEgZyJlnodsaf”
Enter a Team Drive ID> 1 #多個團隊盤,選擇是哪一個
[googlepan1]
type = drive
scope = drive
token = {“access_token”:”ya29.a0Ae4lvC3S4gpa3jiQzypd8-cqQ_L4J2ROVXdsafsd0jd9hNaXy_2G_z1mHrsP5KgZRNCb5uG3rmIJC6r8AjPg2EBdKTB6pAnwy56-kPnsL8-E3Rx77_efreY7LrWTLR5btnAuSgeXb_DKycTDc”,”token_type”:”Bearer”,”refresh_token”:”1//0hdsafasdBM6CgYIARAAGBESNwF-L9IrCEv9WpzWi18y1OnktS6w2gLpo16SAzhTiQd8eLkxTWW2Tmg3SPAWOs90dC8jfkuddDT0″,”expiry”:”2020-04-10T03:04:22.461408986Z”}
team_drive = 0ACwUIdUffa-CUk9PVA
y) Yes this is OK (default)
e) Edit this remote
d) Delete this remote
y/e/d> y #需要有編輯許可權
Current remotes:
Name Type
==== ====
googlepan1 drive
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 #退出