24 个版本 (重大更新)
0.19.0 | 2022 年 6 月 19 日 |
---|---|
0.17.1 | 2022 年 6 月 16 日 |
#1237 in HTTP 服务器
每月 36 次下载
100KB
2K SLoC
杜夫(已重命名为:Dufs)
注意:duf crate 将不再更新,请查看 dufs crate 以获取最新版本。
杜夫是一个简单的文件服务器。支持静态服务、搜索、上传、WebDAV...
特性
- 服务静态文件
- 将文件夹下载为 zip 文件
- 上传文件和文件夹(拖放)
- 搜索文件
- 部分响应(并行/恢复下载)
- 路径级访问控制
- 支持 https
- 支持 WebDAV
- 易于与 curl 一起使用
安装
使用 cargo
cargo install duf
使用 docker
docker run -v `pwd`:/data -p 5000:5000 --rm -it sigoden/duf /data
在 macOS、Linux、Windows 上提供二进制文件
从 GitHub 发布 下载,解压并将 duf 添加到您的 $PATH。
命令行界面
Duf is a simple file server. - https://github.com/sigoden/duf
USAGE:
duf [OPTIONS] [--] [path]
ARGS:
<path> Path to a root directory for serving files [default: .]
OPTIONS:
-b, --bind <addr>... Specify bind address
-p, --port <port> Specify port to listen on [default: 5000]
--path-prefix <path> Specify an url path prefix
-a, --auth <rule>... Add auth for path
-A, --allow-all Allow all operations
--allow-upload Allow upload files/folders
--allow-delete Allow delete files/folders
--allow-symlink Allow symlink to files/folders outside root directory
--enable-cors Enable CORS, sets `Access-Control-Allow-Origin: *`
--render-index Render index.html when requesting a directory
--render-try-index Render index.html if it exists when requesting a directory
--render-spa Render for single-page application
--tls-cert <path> Path to an SSL/TLS certificate to serve with HTTPS
--tls-key <path> Path to the SSL/TLS certificate's private key
-h, --help Print help information
-V, --version Print version information
示例
服务当前工作目录,不允许上传/删除
duf
允许上传/删除
duf -A
监听指定端口
duf -p 80
对于单页应用程序(SPA)
duf --render-spa
使用 https
duf --tls-cert my.crt --tls-key my.key
API
下载文件
curl http://127.0.0.1:5000/path-to-file
将文件夹作为 zip 文件下载
curl -o path-to-folder.zip http://127.0.0.1:5000/path-to-folder?zip
上传文件
curl --upload-file path-to-file http://127.0.0.1:5000/path-to-file
删除文件/文件夹
curl -X DELETE http://127.0.0.1:5000/path-to-file
详细信息
1. 控制渲染逻辑
默认的渲染逻辑是
- 如果请求文件夹,则渲染目录列表。
- 如果请求文件,则渲染文件。
- 如果请求的目标不存在,则返回 404。
使用 --render-*
选项更改渲染逻辑
--render-index
:如果请求文件夹,则在该文件夹中渲染 index.html。如果 index.html 文件不存在,则返回 404。--render-try-index
:类似于--render-index
,如果 index.html 文件不存在,则渲染目录列表,而不是返回 404。--render-spa
:如果请求的目标不存在,则渲染/index.html
2. 路径级访问控制
duf -a <path>@<readwrite>[@<readonly>]
<path>
:受保护的路径<readwrite>
:具有读写权限的账户,必需<readonly>
:具有只读权限的账户,可选
*
作为<readonly>
意味着<path>
是公开的,任何人都可以访问/下载。
例如
duf -a /@admin:pass@* -a /ui@designer:pass1 -A
- 所有文件/文件夹都公开可访问/下载。
- 账户
admin:pass
可以上传/删除/下载任何文件/文件夹。 - 账户
designer:pass1
可以在ui
文件夹中上传/删除/下载任何文件/文件夹。
Curl带摘要认证
curl --digest -u designer:pass1 http://127.0.0.1:5000/ui/path-to-file
许可证
版权所有(c)2022 duf-developers。
duf可在MIT许可证或Apache许可证2.0的条款下提供,任选其一。
请参阅LICENSE-APACHE和LICENSE-MIT文件以获取许可证详细信息。
依赖项
~23–36MB
~633K SLoC