WebDAV
路径指定为 remote:path
。
路径可以按需设置深度,例如 remote:directory/subdirectory
。
配置
要配置 WebDAV 远程存储,你需要有它的 URL、用户名和密码。如果你知道要连接的系统类型,rclone 可以启用额外的功能。
以下是一个如何创建名为 remote
的远程存储的示例。首先运行:
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
配置完成后,你可以像这样使用 rclone
:
列出 WebDAV 根目录下的所有目录
rclone lsd remote:
列出 WebDAV 中的所有文件
rclone ls remote:
将本地目录复制到 WebDAV 中名为 backup
的目录
rclone copy /home/source remote:backup
修改时间和哈希值
普通的 WebDAV 不支持修改时间。然而,当与 Fastmail Files、Owncloud 或 Nextcloud 一起使用时,rclone 将支持修改时间。
同样,普通的 WebDAV 不支持哈希值,但当与 Fastmail Files、Owncloud 或 Nextcloud 一起使用时,rclone 将支持 SHA1 和 MD5 哈希值。根据 Owncloud 或 Nextcloud 的具体版本,哈希值可能会出现在所有对象上,或者仅出现在上传时带有哈希值的对象上。
标准选项
以下是 WebDAV 特有的标准选项。
–webdav-url
要连接的 HTTP 主机的 URL。
例如 https://example.com
。
属性:
- 配置项: url
- 环境变量: RCLONE_WEBDAV_URL
- 类型: 字符串
- 是否必需: 是
–webdav-vendor
你正在使用的 WebDAV 站点、服务或软件的名称。
属性:
- 配置项: vendor
- 环境变量: RCLONE_WEBDAV_VENDOR
- 类型: 字符串
- 是否必需: 否
- 示例:
- “fastmail”
- Fastmail Files
- “nextcloud”
- Nextcloud
- “owncloud”
- Owncloud
- “sharepoint”
- 通过 Microsoft 账户认证的 SharePoint Online
- “sharepoint-ntlm”
- 使用 NTLM 认证的 SharePoint,通常是自托管或本地部署的
- “rclone”
- 通过 WebDAV 协议通过 HTTP 提供远程服务的 rclone WebDAV 服务器
- “other”
- 其他站点、服务或软件
- “fastmail”
–webdav-user
用户名。
如果使用 NTLM 认证,用户名应采用 Domain\User
的格式。
属性:
- 配置项: user
- 环境变量: RCLONE_WEBDAV_USER
- 类型: 字符串
- 是否必需: 否
–webdav-pass
密码。
注意:输入此选项的值必须进行加密处理 - 请参阅 rclone obscure。
属性:
- 配置项: pass
- 环境变量: RCLONE_WEBDAV_PASS
- 类型: 字符串
- 是否必需: 否
–webdav-bearer-token
替代用户名/密码的令牌(例如 Macaroon)。
属性:
- 配置项: bearer_token
- 环境变量: RCLONE_WEBDAV_BEARER_TOKEN
- 类型: 字符串
- 是否必需: 否
高级选项
以下是 WebDAV 特有的高级选项。
–webdav-bearer-token-command
用于获取令牌的命令。
属性:
- 配置项: bearer_token_command
- 环境变量: RCLONE_WEBDAV_BEARER_TOKEN_COMMAND
- 类型: 字符串
- 是否必需: 否
–webdav-encoding
后端的编码方式。
有关更多信息,请参阅 概述中的编码部分。
对于 sharepoint-ntlm
,默认编码为 Slash,LtGt,DoubleQuote,Colon,Question,Asterisk,Pipe,Hash,Percent,BackSlash,Del,Ctl,LeftSpace,LeftTilde,RightSpace,RightPeriod,InvalidUtf8
,否则为 identity
。
属性:
- 配置项: encoding
- 环境变量: RCLONE_WEBDAV_ENCODING
- 类型: 字符串
- 是否必需: 否
–webdav-headers
为所有事务设置 HTTP 头。
使用此选项为所有事务设置额外的 HTTP 头。
输入格式为逗号分隔的键值对列表。可以使用标准的 CSV 编码。
例如,要设置一个 Cookie,可以使用 'Cookie,name=value'
或 '"Cookie","name=value"'
。
你可以设置多个头,例如 '"Cookie","name=value","Authorization","xxx"'
。
属性:
- 配置项: headers
- 环境变量: RCLONE_WEBDAV_HEADERS
- 类型: CommaSepList
- 默认值:
–webdav-pacer-min-sleep
API 调用之间的最小睡眠时间。
属性:
- 配置项: pacer_min_sleep
- 环境变量: RCLONE_WEBDAV_PACER_MIN_SLEEP
- 类型: 持续时间
- 默认值: 10ms
–webdav-nextcloud-chunk-size
Nextcloud 上传块大小。
我们建议将你的 Nextcloud 实例配置为将最大块大小增加到 1 GB,以获得更好的上传性能。 请参阅 https://docs.nextcloud.com/server/latest/admin_manual/configuration_files/big_file_upload_configuration.html#adjust-chunk-size-on-nextcloud-side
设置为 0 可禁用分块上传。
属性:
- 配置项: nextcloud_chunk_size
- 环境变量: RCLONE_WEBDAV_NEXTCLOUD_CHUNK_SIZE
- 类型: 大小后缀
- 默认值: 10Mi
–webdav-owncloud-exclude-shares
排除 Owncloud 共享。
属性:
- 配置项: owncloud_exclude_shares
- 环境变量: RCLONE_WEBDAV_OWNCLOUD_EXCLUDE_SHARES
- 类型: 布尔值
- 默认值: false
–webdav-owncloud-exclude-mounts
排除 Owncloud 挂载的存储。
属性:
- 配置项: owncloud_exclude_mounts
- 环境变量: RCLONE_WEBDAV_OWNCLOUD_EXCLUDE_MOUNTS
- 类型: 布尔值
- 默认值: false
–webdav-unix-socket
要连接的 Unix 域套接字的路径,而不是直接打开 TCP 连接。
属性:
- 配置项: unix_socket
- 环境变量: RCLONE_WEBDAV_UNIX_SOCKET
- 类型: 字符串
- 是否必需: 否
–webdav-auth-redirect
在重定向时保留认证信息。
如果服务器在 rclone 尝试读取文件时将其重定向到新域名,通常 rclone 会从请求中删除 Authorization
头。
这是标准的安全做法,以避免将你的凭据发送到未知的 Web 服务器。
然而,在某些情况下,这是可取的。如果你在 rclone 尝试从 WebDAV 服务器读取文件时遇到类似 “401 Unauthorized” 的错误,你可以尝试此选项。
属性:
- 配置项: auth_redirect
- 环境变量: RCLONE_WEBDAV_AUTH_REDIRECT
- 类型: 布尔值
- 默认值: false
–webdav-description
远程存储的描述。
属性:
- 配置项: description
- 环境变量: RCLONE_WEBDAV_DESCRIPTION
- 类型: 字符串
- 是否必需: 否
供应商说明
以下是特定供应商的说明。
Fastmail Files
使用 https://webdav.fastmail.com/
或其子目录作为 URL,并使用你的 Fastmail 电子邮件 [email protected]
作为用户名。
按照 此文档 创建具有 Files (WebDAV)
访问权限的应用密码,并将其用作密码。
Fastmail 使用 X-OC-Mtime
头支持修改时间。
Owncloud
点击页面右下角的设置齿轮,这将显示 rclone 在配置步骤中所需的 WebDAV URL。它看起来类似于 https://example.com/remote.php/webdav/
。
Owncloud 使用 X-OC-Mtime
头支持修改时间。
Nextcloud
其配置方式与 Owncloud 相同。请注意,Nextcloud 最初不支持文件流传输(rcat
),而 Owncloud 支持,但 此问题 似乎在 2020 年 11 月 27 日已修复(使用 rclone v1.53.1 和 Nextcloud Server v19 进行了测试)。
Sharepoint Online
Rclone 可用于 OneDrive for Business 或 Office365 教育账户提供的 SharePoint。 此功能仅适用于其中一些账户,主要是 Office365 教育账户。这些账户有时未经过域名所有者的验证 github#1975
这意味着这些账户无法使用官方 API 添加(其他账户应使用 “onedrive” 选项)。然而,可以使用 WebDAV 访问它们。
要在 rclone 中使用 SharePoint 远程存储,请按以下方式添加: 首先,你需要获取远程存储的 URL:
- 访问 此处 打开你的 OneDrive 或登录
- 现在查看你的地址栏,URL 应类似于:
https://[YOUR-DOMAIN]-my.sharepoint.com/personal/[YOUR-EMAIL]/_layouts/15/onedrive.aspx
你只需要此 URL 到电子邮件地址部分。之后,你很可能需要添加 /Documents
。该子目录包含存储在你 OneDrive 上的实际数据。
按以下方式将远程存储添加到 rclone:
将 url
配置为 https://[YOUR-DOMAIN]-my.sharepoint.com/personal/[YOUR-EMAIL]/Documents
,并使用你的普通账户电子邮件和密码作为 user
和 pass
。
如果你启用了 2FA,则必须生成一个应用密码。
将 vendor
设置为 sharepoint
。
你的配置文件应如下所示:
[sharepoint]
type = webdav
url = https://[YOUR-DOMAIN]-my.sharepoint.com/personal/[YOUR-EMAIL]/Documents
vendor = sharepoint
user = YourEmailAddress
pass = encryptedpassword
使用 NTLM 认证的 SharePoint
如果你的(托管)SharePoint 未与 OneDrive 账户关联,且使用 NTLM 认证,则可以使用此选项。
要获取 url
配置,与上述情况类似,首先在浏览器中导航到所需目录以获取 URL,然后删除打开目录名称之后的所有内容。
示例: 如果 URL 是: https://example.sharepoint.com/sites/12345/Documents/Forms/AllItems.aspx
要使用的配置应为: https://example.sharepoint.com/sites/12345/Documents
将 vendor
设置为 sharepoint-ntlm
。
NTLM 使用域名和用户名组合进行认证,
将 user
设置为 DOMAIN\username
。
你的配置文件应如下所示:
[sharepoint]
type = webdav
url = https://[YOUR-DOMAIN]/some-path-to/Documents
vendor = sharepoint-ntlm
user = DOMAIN\user
pass = encryptedpassword
SharePoint 所需的标志
由于 SharePoint 对上传的文档有一些特殊处理,你无法使用文档大小或文档哈希值来比较文件自上传后是否有更改,或者判断哪个文件更新。
对于从 SharePoint 复制文件(尤其是 .docx、.xlsx 等 Office 文件)到其他位置或从其他位置复制到 SharePoint 的 Rclone 调用(如 copy
、sync
等),你应该添加这些标志,以确保 Rclone 使用“最后修改”日期时间属性来比较你的文档:
--ignore-size --ignore-checksum --update
Rclone
如果你通过 rclone 提供的 WebDAV 来托管远程存储,请使用此选项。 更多详细信息请阅读 rclone serve webdav。
rclone serve 使用 X-OC-Mtime
头支持修改时间。
dCache
dCache 是一个支持多种协议和认证/授权方案的存储系统。对于 WebDAV 客户端,它允许用户使用用户名和密码(基本认证)、X.509 证书、Kerberos 以及各种承载令牌(包括 Macaroons 和 OpenID Connect 访问令牌)进行认证。
使用 other
类型进行常规配置。不要输入用户名或密码,而是将你的 Macaroon 作为 bearer_token
输入。
最终的配置大致如下所示。
[dcache]
type = webdav
url = https://dcache...
vendor = other
user =
pass =
bearer_token = your-macaroon
有一个脚本可以从 dCache WebDAV 端点获取 Macaroon 并创建一个 rclone 配置文件。
也可以从 dCache 附带的 dCacheView 网络浏览器/JavaScript 客户端获取 Macaroon。
OpenID 连接
dCache 还支持使用 OpenID 连接访问令牌进行身份验证。 OpenID 连接是一种基于 OAuth 2.0 的协议,它允许服务识别已经通过某个中央服务进行身份验证的用户。
rclone 目前通过另一个名为 [oidc - agent](https://github.com/indigo - dc/oidc - agent) 的软件包来支持 OpenID 连接。这是一个命令行工具,用于方便地获取访问令牌。安装并配置完成后,可以通过运行 oidc - token
命令来获取访问令牌。以下示例展示了从 XDC OpenID 连接提供商获取的(缩短后的)访问令牌。
paul@celebrimbor:~$ oidc-token XDC
eyJraWQ[...]QFXDt0
paul@celebrimbor:~$
注意 在 oidc-token
命令能够正常工作之前,必须将刷新令牌加载到 oidc 代理中。这可以通过 oidc-add
命令来完成(例如,oidc-add XDC
)。通常,每个登录会话只需执行一次此操作。有关这方面的详细信息以及如何在 OIDC 提供商处注册 oidc 代理,请参阅 oidc 代理文档。
rclone 的 bearer_token_command
配置选项用于从 oidc 代理获取访问令牌。
将其配置为普通的 WebDAV 端点,选择“other”供应商,将用户名和密码留空。当系统提示时,选择编辑高级配置,并输入获取承载令牌的命令(例如,oidc-agent XDC
)。
以下示例配置展示了一个使用 oidc 代理从 XDC OIDC 提供商获取访问令牌的 WebDAV 端点。
[dcache]
type = webdav
url = https://dcache.example.org/
vendor = other
bearer_token_command = oidc-token XDC