使用rclone上传文件到站内网盘

本站的网盘非常好用,就是偶尔上传不稳定,大文件容易失败。使用rclone上传可以断点续传、自动重试,非常方便。

1.首先安装rclone,不同平台有不同的安装方法,有问题可以问AI。

2.然后运行:

rclone config

按提示设置:

No remotes found, make a new one?
n) New remote
s) Set configuration password
q) Quit config
n/s/q> n
name> remote
Type of storage to configure.
Choose a number from below, or type in your own value
[snip]
XX / WebDAV
   \ "webdav"
[snip]
Storage> webdav
URL of http host to connect to
Choose a number from below, or type in your own value
 1 / Connect to example.com
   \ "https://example.com"
url> https://example.com/remote.php/webdav/
Name of the WebDAV site/service/software you are using
Choose a number from below, or type in your own value
 1 / Fastmail Files
   \ (fastmail)
 2 / Nextcloud
   \ (nextcloud)
 3 / Owncloud
   \ (owncloud)
 4 / Sharepoint Online, authenticated by Microsoft account
   \ (sharepoint)
 5 / Sharepoint with NTLM authentication, usually self-hosted or on-premises
   \ (sharepoint-ntlm)
 6 / rclone WebDAV server to serve a remote over HTTP via the WebDAV protocol
   \ (rclone)
 7 / Other site/service or software
   \ (other)
vendor> 2
User name
user> user
Password.
y) Yes type in my own password
g) Generate random password
n) No leave this optional password blank
y/g/n> y
Enter the password:
password:
Confirm the password:
password:
Bearer token instead of user/pass (e.g. a Macaroon)
bearer_token>
Remote config
Configuration complete.
Options:
- type: webdav
- url: https://example.com/remote.php/webdav/
- vendor: nextcloud
- user: user
- pass: *** ENCRYPTED ***
- bearer_token:
Keep this "remote" remote?
y) Yes this is OK
e) Edit this remote
d) Delete this remote
y/e/d> y

3.配置好之后就可以像这样使用 rclone (remote替换成你设置的名称):

1)列出网盘顶层的所有目录:

rclone lsd remote:

2)上传本地的目录/home/source到网盘的目录/backup

rclone copy /home/source remote:backup

3)还有很多可选参数,比如:

rclone copy a.mdx remote:mymdx \
    --webdav-nextcloud-chunk-size 50M \
    --timeout 10m \
    --contimeout 10m \
    --retries 10 \
    -P

核心操作

  • rclone copy a.mdx remote:mymdx
    这是命令的主体。它的作用是将你当前目录下的本地文件 a.mdx,复制(上传)到名为 remote 的网盘中,保存在网盘的 mymdx 文件夹下。如果 mymdx 文件夹不存在,rclone 会自动创建它。

针对 Nextcloud/WebDAV 的优化

  • –webdav-nextcloud-chunk-size 50M
    作用:大文件分片。 默认情况下,rclone 会直接将整个文件作为一个数据流发送。加上这个参数后,rclone 会强制把大文件切分成一个个 50MB 的小数据块(Chunks)依次上传。
    目的: 很多 WebDAV 服务器(如 Nginx 反向代理)会限制单次请求的最大文件体积。将其切成 50M 的小块,可以完美绕过这种服务器端的体积限制。

网络连接与超时控制

  • –timeout 10m
    作用:IO 空闲超时。 意思是“如果传输过程中卡住了,超过 10 分钟(10m)没有任何数据流动,就认为连接已经死了并断开”。默认值通常比较短,设为 10 分钟可以容忍极端的网络卡顿。

  • –contimeout 10m
    作用:建立连接超时。 意思是“在最开始尝试连接服务器时,如果服务器 10 分钟都没有响应,才宣布连接失败”。这对于响应缓慢的服务器非常有用。

容错与重试机制

  • –retries 10
    作用:整体重试次数。 如果上传过程中因为任何网络或服务器原因彻底失败了,rclone 不会直接罢工报错,而是会自动重新尝试最多 10 次

显示效果

  • -P
    作用:显示进度条。 它是 --progress 的缩写形式。加上它,你的终端界面才会实时显示当前的传输速度、已传输的大小、剩余时间以及成功率等信息,否则 rclone 会在后台默默执行,终端什么都不显示。

用 webdav 软件如 cyberduck 是比较稳定的,也有GUI。

学习了

上传碰到问题的诸位可看看