阿里云盘的webdav协议开源实现

介绍

本项目实现了阿里云盘的webdav协议,只需要简单的配置一下,就可以让阿里云盘变身为webdav协议的文件服务器。 基于此,你可以把阿里云盘挂载为Windows、Linux、Mac系统的磁盘,可以通过NAS系统做文件管理或文件同步,更多玩法等你挖掘

如何使用

支持refreshToken登录方式,具体看参数说明

运行

点击下载

选择对应的版本进行下载,进入到解压目录执行

./webdav -rt="your refreshToken"

参数说明

-rt
    阿里云盘的refreshToken,获取方式见下文
-port
    非必填,服务器端口号,默认为8085
-user
    WebDav账户,默认admin
-pwd
    WebDav密码,默认123456
    

客户端兼容性

客户端 下载 上传 备注
Rclone 可用 可用 推荐,支持各个系统
Mac原生 可用 可用 适配有问题,不建议使用
Windows原生 可用 有点小问题 不建议,适配有点问题,上传报错
RaiDrive 可用 可用 Windows平台下建议用这个

openwrt ui

项目路径

浏览器获取refreshToken方式

  1. 先通过浏览器(建议chrome)打开阿里云盘官网并登录:https://www.aliyundrive.com/drive/
  2. 登录成功后,按F12打开开发者工具,点击Application,点击Local Storage,点击 Local Storage下的 https://www.aliyundrive.com/,点击右边的token,此时可以看到里面的数据,其中就有refresh_token,把其值复制出来即可。(格式为小写字母和数字,不要复制双引号。例子:ca6bf2175d73as2188efg81f87e55f11)
  3. 第二步有点繁琐,大家结合下面的截图就看懂了 image

功能说明

支持的功能

  1. 查看文件夹、查看文件
  2. 文件移动目录
  3. 文件重命名
  4. 文件下载
  5. 文件删除
  6. 文件上传
  7. 支持WebDav权限校验(默认账户密码:admin/123456)
  8. 文件在线编辑
  9. Webdav下的流媒体播放等功能

已知问题

  1. 没有做文件sha1校验,不保证上传文件的100%准确性(一般场景下,是没问题的)
  2. 通过文件名和文件大小判断是否重复。也就是说如果一个文件即使发生了更新,但其大小没有任何改变,是不会自动上传的
  3. 不支持文件名包含 / 字符
  4. 部分客户端兼容性不好

免责声明

  1. 本软件为免费开源项目,无任何形式的盈利行为。
  2. 本软件服务于阿里云盘,旨在让阿里云盘功能更强大。如有侵权,请与我联系,会及时处理。
  3. 本软件皆调用官方接口实现,无任何“Hack”行为,无破坏官方接口行为。
  4. 本软件仅做流量转发,不拦截、存储、篡改任何用户数据。
  5. 严禁使用本软件进行盈利、损坏官方、散落任何违法信息等行为。
  6. 本软件不作任何稳定性的承诺,如因使用本软件导致的文件丢失、文件破坏等意外情况,均与本软件无关。
Comments
  • 使用rclone挂载,只显示第一层文件夹,而且所有文件夹内容都是空

    使用rclone挂载,只显示第一层文件夹,而且所有文件夹内容都是空

    • 测试环境:Windows 10 Enterprise LTSC
    • 启动命令 webdav -rt mytoken -port 8080
    • rclone启动命令 rclone mount aliyun:/ Z: --cache-dir d:\tmp --vfs-cache-mode writes --config .\rclone.conf

    在资源管理器中查看Z盘,只能显示第一层文件夹,而且所有文件夹内容都是空。

    附 http://127.0.0.1:8080/ 返回结果 127.0.0.1.xml.txt

  • 获取quota信息不对

    获取quota信息不对

    Linux 下面 df 命令,获取到的数据不对。 这个命令对应的 rclone 的请求包是:

    PROPFIND / HTTP/1.1
    Host: 127.0.0.1:8085
    User-Agent: rclone/v1.56.0
    Content-Length: 139
    Authorization: Basic YWRtaW46MTIzNDU2
    Depth: 0
    Referer: http://127.0.0.1:8085/
    Accept-Encoding: gzip
    
    <?xml version="1.0" ?>
    <D:propfind xmlns:D="DAV:">
     <D:prop>
      <D:quota-available-bytes/>
      <D:quota-used-bytes/>
     </D:prop>
    </D:propfind>
    

    而返回的应包含quota信息,当前是404.。

    <?xml version="1.0" encoding="UTF-8"?><D:multistatus xmlns:D="DAV:"><D:response><D:href>/</D:href><D:propstat><D:prop><D:quota-available-bytes></D:quota-available-bytes><D:quota-used-bytes></D:quota-used-bytes></D:prop><D:status>HTTP/1.1 404 Not Found</D:status></D:propstat></D:response><D:response><D:href>/APP</D:href><D:propstat><D:prop><D:quota-available-bytes></D:quota-available-bytes><D:quota-used-bytes></D:quota-used-bytes></D:prop><D:status>HTTP/1.1 404 Not Found</D:status></D:propstat></D:response><D:response><D:href>/movie</D:href><D:propstat><D:prop><D:quota-available-bytes></D:quota-available-bytes><D:quota-used-bytes></D:quota-used-bytes></D:prop><D:status>HTTP/1.1 404 Not Found</D:status></D:propstat></D:response><D:response><D:href>/STARS-160.mp4</D:href><D:propstat><D:prop><D:quota-available-bytes></D:quota-available-bytes><D:quota-used-bytes></D:quota-used-bytes></D:prop><D:status>HTTP/1.1 404 Not Found</D:status></D:propstat></D:response><D:response><D:href>/base.apk</D:href><D:propstat><D:prop><D:quota-available-bytes></D:quota-available-bytes><D:quota-used-bytes></D:quota-used-bytes></D:prop><D:status>HTTP/1.1 404 Not Found</D:status></D:propstat></D:response></D:multistatus>
    
    

    抓包 rs 版本返回的内容是这样:

    <?xml version="1.0" encoding="utf-8"?><D:multistatus xmlns:D="DAV:"><D:response><D:href>/</D:href><D:propstat><D:prop><D:quota-available-bytes>1056194496917</D:quota-available-bytes><D:quota-used-bytes>60497000043</D:quota-used-bytes></D:prop><D:status>HTTP/1.1 200 OK</D:status></D:propstat></D:response>
    </D:multistatus>
    
  • 用来同步时遇到的问题

    用来同步时遇到的问题

    在 SwiftBackup 用 webdav 登录时会先发送 HEAD /SwiftBackup 测试文件是否存在。

    但文件不存在,不会返回 NotFound。导致 SwiftBackup 不会初始化文件。


    另一个问题

    refresh token 时,更新失败(例如断网时,执行下面的命令)也会更新 token 文件,导致 token 文件被清空

    ./go-aliyun-webdav -rt=path/to/token/file
    
  • mipsle架构 int 类型是 int32, 有没办法搞搞呢?

    mipsle架构 int 类型是 int32, 有没办法搞搞呢?

    现在有文件比较大,ls 命令的时候 提示json报错: json: cannot unmarshal number 2181845910 into Go struct field ListModel.items.size of type int

    写了验证的方法:

    package main
    import (
    	"fmt"
    	"math"
    )
    func main(){
        fmt.Printf("max int64   = %+v\n", math.MaxInt64)
        fmt.Printf("max int32   = %+v\n", math.MaxInt32)
        fmt.Printf("max int16   = %+v\n", math.MaxInt16)
    
        // integer min
        // fmt.Printf("min int64   = %+v\n", math.MinInt64)
        fmt.Printf("min int32   = %+v\n", math.MinInt32)
    
        fmt.Printf("max float64 = %+v\n", math.MaxFloat64)
        fmt.Printf("max float32 = %+v\n", math.MaxFloat32)
    
    }
    

    build的时候就提示 overflows.

    [yorks@yypc main]$ GOARCH=mipsle go build -ldflags "-s -w" -o testint
    # main
    ./main.go:7:16: constant 9223372036854775807 overflows int
    

    也就是说这个cpu架构的int是 int32 . 但是文件大小可能会有超过int32的长度,有没办法搞搞?

  • 不显示目录

    不显示目录

    chrome 浏览器 不是根目录什么都不显示

    根目录显示以下内容 This XML file does not appear to have any style information associated with it. The document tree is shown below. <D:multistatus xmlns:D="DAV:"> <D:response> <D:href>/</D:href> <D:propstat> <D:prop> <D:supportedlock> <D:lockentry xmlns:D="DAV:"> <D:lockscope> <D:exclusive/> </D:lockscope> <D:locktype> <D:write/> </D:locktype> </D:lockentry> </D:supportedlock> <D:resourcetype> <D:collection xmlns:D="DAV:"/>

  • 不支持新建文件夹,请加入这一功能!

    不支持新建文件夹,请加入这一功能!

    Describe the bug A clear and concise description of what the bug is.

    To Reproduce Steps to reproduce the behavior:

    1. Go to '...'
    2. Click on '....'
    3. Scroll down to '....'
    4. See error

    Expected behavior A clear and concise description of what you expected to happen.

    Screenshots If applicable, add screenshots to help explain your problem.

    Desktop (please complete the following information):

    • OS: [e.g. iOS]
    • Browser [e.g. chrome, safari]
    • Version [e.g. 22]

    Smartphone (please complete the following information):

    • Device: [e.g. iPhone6]
    • OS: [e.g. iOS8.1]
    • Browser [e.g. stock browser, safari]
    • Version [e.g. 22]

    Additional context Add any other context about the problem here.

  • macos系统下,挂载网盘后,新建文件夹会不停的建立好多文件夹

    macos系统下,挂载网盘后,新建文件夹会不停的建立好多文件夹

    Describe the bug截屏2022-01-06 下午8 24 23A clear and concise description of what the bug is.

    To Reproduce截屏2022-01-06 下午8 24 23Steps to reproduce the behavior:

    1. Go to '...'
    2. Click on '....'
    3. Scroll down to '....'
    4. See error

    Expected behavior A clear and concise description of what you expected to happen.

    Screenshots If applicable, add screenshots to help explain your problem.

    Desktop (please complete the following information):

    • OS: [e.g. iOS]
    • Browser [e.g. chrome, safari]
    • Version [e.g. 22]

    Smartphone (please complete the following information):

    • Device: [e.g. iPhone6]
    • OS: [e.g. iOS8.1]
    • Browser [e.g. stock browser, safari]
    • Version [e.g. 22]

    Additional context Add any other context about the problem here.

  • 99999

    99999

    Describe the bug A clear and concise description of what the bug is.

    To Reproduce Steps to reproduce the behavior:

    1. Go to '...'
    2. Click on '....'
    3. Scroll down to '....'
    4. See error

    Expected behavior A clear and concise description of what you expected to happen.

    Screenshots If applicable, add screenshots to help explain your problem.

    Desktop (please complete the following information):

    • OS: [e.g. iOS]
    • Browser [e.g. chrome, safari]
    • Version [e.g. 22]

    Smartphone (please complete the following information):

    • Device: [e.g. iPhone6]
    • OS: [e.g. iOS8.1]
    • Browser [e.g. stock browser, safari]
    • Version [e.g. 22]

    Additional context Add any other context about the problem here.

  • 88888

    88888

    Describe the bug A clear and concise description of what the bug is.

    To Reproduce Steps to reproduce the behavior:

    1. Go to '...'
    2. Click on '....'
    3. Scroll down to '....'
    4. See error

    Expected behavior A clear and concise description of what you expected to happen.

    Screenshots If applicable, add screenshots to help explain your problem.

    Desktop (please complete the following information):

    • OS: [e.g. iOS]
    • Browser [e.g. chrome, safari]
    • Version [e.g. 22]

    Smartphone (please complete the following information):

    • Device: [e.g. iPhone6]
    • OS: [e.g. iOS8.1]
    • Browser [e.g. stock browser, safari]
    • Version [e.g. 22]

    Additional context Add any other context about the problem here.

  • ddddd

    ddddd

    Describe the bug A clear and concise description of what the bug is.

    To Reproduce Steps to reproduce the behavior:

    1. Go to '...'
    2. Click on '....'
    3. Scroll down to '....'
    4. See error

    Expected behavior A clear and concise description of what you expected to happen.

    Screenshots If applicable, add screenshots to help explain your problem.

    Desktop (please complete the following information):

    • OS: [e.g. iOS]
    • Browser [e.g. chrome, safari]
    • Version [e.g. 22]

    Smartphone (please complete the following information):

    • Device: [e.g. iPhone6]
    • OS: [e.g. iOS8.1]
    • Browser [e.g. stock browser, safari]
    • Version [e.g. 22]

    Additional context Add any other context about the problem here.

  • 333333

    333333

    Describe the bug A clear and concise description of what the bug is.

    To Reproduce Steps to reproduce the behavior:

    1. Go to '...'
    2. Click on '....'
    3. Scroll down to '....'
    4. See error

    Expected behavior A clear and concise description of what you expected to happen.

    Screenshots If applicable, add screenshots to help explain your problem.

    Desktop (please complete the following information):

    • OS: [e.g. iOS]
    • Browser [e.g. chrome, safari]
    • Version [e.g. 22]

    Smartphone (please complete the following information):

    • Device: [e.g. iPhone6]
    • OS: [e.g. iOS8.1]
    • Browser [e.g. stock browser, safari]
    • Version [e.g. 22]

    Additional context Add any other context about the problem here.

  • 运行起来了,windows怎么访问呢

    运行起来了,windows怎么访问呢

    如图,浏览器可以正常打开http://localhost:8085/,windows自带的资源管理器添加网络映射提示文件夹无效。 注册表HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\WebClient\Parameters 也把BasicAuthLevel 值改成2了 求教 image

  • 删除文件夹很慢,有时候无效。

    删除文件夹很慢,有时候无效。

    Describe the bug 删除文件夹很慢,有时候删除后,被删除的文件夹会自动“恢复”,其实根本没有删除。 我是用RaiDriver挂载的。 Desktop (please complete the following information):

    • OS: [Win11,简体中文专业工作站版22000.556]
  • 一旦刷新 token 失败就无法使用,建议加入自动重试

    一旦刷新 token 失败就无法使用,建议加入自动重试

    Mar 19 21:07:00 webdav-ali[3157]: Post "https://api.aliyundrive.com/token/refresh": dial tcp: lookup api.aliyundrive.com on 127.0.0.1:53: server misbehaving
    Mar 19 21:07:00 webdav-ali[3157]: 刷新token失败
    

    使用场景:在本地搭建了 DNS 服务器,刷新 token 时,DNS 没有启动,因此失败,此后一直没有自动刷新。DNS 上线后,手动重启可以正常使用。

    可以预想到,一旦网络出现故障,token 刷新失败,就再也无法使用了。