GitHub开源的轻量级文件服务器,可docker一键部署

介绍

项目github官网地址

Dufs是一款由Rust编写的轻量级文件服务器,不仅支持静态文件服务,还能轻松上传、下载、搜索文件,甚至支持WebDAV,让我们通过Web方式远程管理文件变得轻而易举。而且,它跨平台,无论是Windows、macOS还是Linux,都能轻松驾驭

性能特色

  • 静态文件服务:一键开启,让你的文件触手可及。
  • 上传下载:支持拖放上传,文件夹打包下载为zip,省时又省力。
  • 文件操作:创建、编辑、搜索文件,一切尽在掌握。
  • 断点续传:再也不用担心大文件传输中断了,Dufs支持断点续传,让你的下载上传无忧。
  • 访问控制:灵活的权限设置,无论是公开分享还是私密访问,都能轻松搞定。
  • HTTPS & WebDAV:安全传输,远程管理,一个都不能少。

安装使用

Ubuntu2404-server

该项目支持多平台安装,这里我使用docker进行快速搭建

root@huhy:~# docker images
REPOSITORY       TAG       IMAGE ID       CREATED        SIZE
sigoden/dufs     latest    f7f212903ad7   3 months ago   4.37MB
docker run -v `pwd`:/data -p 5000:5000 --rm sigoden/dufs /data -A
  • -v \pwd:/data:

    • -v: 这是用于挂载卷的选项。
    • pwd: 这是一个命令替换,返回当前工作目录的路径。
    • :/data: 把主机上的当前目录(由 pwd 命令获取的路径)挂载到容器内的 /data 目录中。这样,容器可以访问主机上的这个目录中的文件。
      -p 5000:5000:
  • -p: 这是用于端口映射的选项。
    5000:5000: 将主机的 5000 端口映射到容器的 5000 端口。这样,主机访问 localhost:5000 时,会转发到容器的 5000 端口。

  • –rm: 这个选项指定在容器停止运行后,自动删除容器。这样可以防止积累不必要的临时容器。

  • sigoden/dufs: Docker 镜像的名称,sigoden/dufs 是镜像的全名,运行的镜像是 sigoden 用户创建的 dufs 镜像。

  • /data: 这是传递给 dufs 程序的第一个参数,表示 dufs 要共享的目录路径(这里指向容器内的 /data 目录,即挂载的主机目录)。

  • -A: 这是传递给 dufs 程序的一个选项,通常用于表示启用身份验证或匿名访问等配置(具体功能取决于 dufs 的实现)

使用home目录作为共享目录:

root@huhy:/home# ls
huhy  sigoden.tar
root@huhy:/home# docker run -v `pwd`:/data -p 5000:5000 --rm sigoden/dufs /data -A
Listening on:
  http://127.0.0.1:5000/
  http://172.17.0.2:5000/
  http://[::1]:5000/

界面IP:5000查看

在这里插入图片描述
win系统可界面上传

在这里插入图片描述

界面创建目录等

在这里插入图片描述

命令使用

命令在docker环境中不能使用,因为该镜像很小,没有bash环境,如果需要使用命令,则使用其他搭建方式,有镜像需要可评论区

修改默认的端口

dufs . -p 8080

共享当前目录并允许所有操作(上传、删除等)

dufs -A  

只允许上传:

dufs --allow-upload 

指定特定目录

dufs temp 

指定文件

dufs temp.doc

制定8080端口

dufs -p 8080

帮助手册

Dufs is a distinctive utility file server - https://github.com/sigoden/dufs

Usage: dufs [OPTIONS] [serve-path]

Arguments:
  [serve-path]  Specific path to serve [default: .]

Options:
  -c, --config <file>        Specify configuration file
  -b, --bind <addrs>         Specify bind address or unix socket
  -p, --port <port>          Specify port to listen on [default: 5000]
      --path-prefix <path>   Specify a path prefix
      --hidden <value>       Hide paths from directory listings, e.g. tmp,*.log,*.lock
  -a, --auth <rules>         Add auth roles, e.g. user:pass@/dir1:rw,/dir2
  -A, --allow-all            Allow all operations
      --allow-upload         Allow upload files/folders
      --allow-delete         Allow delete files/folders
      --allow-search         Allow search files/folders
      --allow-symlink        Allow symlink to files/folders outside root directory
      --allow-archive        Allow zip archive generation
      --enable-cors          Enable CORS, sets `Access-Control-Allow-Origin: *`
      --render-index         Serve index.html when requesting a directory, returns 404 if not found index.html
      --render-try-index     Serve index.html when requesting a directory, returns directory listing if not found index.html
      --render-spa           Serve SPA(Single Page Application)
      --assets <path>        Set the path to the assets directory for overriding the built-in assets
      --log-format <format>  Customize http log format
      --log-file <file>      Specify the file to save logs to, other than stdout/stderr
      --compress <level>     Set zip compress level [default: low] [possible values: none, low, medium, high]
      --completions <shell>  Print shell completion script for <shell> [possible values: bash, elvish, fish, powershell, zsh]
      --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
  -V, --version              Print version

API调用

  1. 上传文件
curl -T path-to-file http://127.0.0.1:5000/new-path/path-to-file
  • -T path-to-file: 上传本地文件 path-to-file 到服务器。
  • http://127.0.0.1:5000/new-path/path-to-file: 将文件上传到服务器的指定路径 new-path/path-to-file。
  1. 下载文件
curl http://127.0.0.1:5000/path-to-file           # download the file
curl http://127.0.0.1:5000/path-to-file?hash      # retrieve the sha256 hash of the file
  • 下载文件: 直接访问文件的 URL 将文件下载到本地。
  • 获取文件的 SHA256 哈希值: 通过在 URL 后添加 ?hash,获取文件的 SHA256 哈希值,而不是文件内容。
  1. 下载文件夹为 ZIP 文件
curl -o path-to-folder.zip http://127.0.0.1:5000/path-to-folder?zip
  • -o path-to-folder.zip: 指定下载后保存的 ZIP 文件名。
  • ?zip: 在文件夹 URL 后添加 ?zip,将该文件夹打包为 ZIP 文件进行下载。
4. 删除文件/文件夹
curl -X DELETE http://127.0.0.1:5000/path-to-file-or-folder
  • -X DELETE: 使用 DELETE 方法删除指定路径的文件或文件夹。
  1. 创建目录
curl -X MKCOL http://127.0.0.1:5000/path-to-folder
  • -X MKCOL: 使用 MKCOL 方法创建一个新的目录。
  1. 移动文件/文件夹
curl -X MOVE http://127.0.0.1:5000/path -H "Destination: http://127.0.0.1:5000/new-path"
  • -X MOVE: 使用 MOVE 方法将文件或文件夹从 path 移动到 new-path。
  • -H “Destination: http://127.0.0.1:5000/new-path”: 指定新的路径(目标路径)。
  1. 列出/搜索目录内容
curl http://127.0.0.1:5000?q=Dockerfile           # search for files, similar to `find -name Dockerfile`
curl http://127.0.0.1:5000?simple                 # output names only, similar to `ls -1`
curl http://127.0.0.1:5000?json                   # output paths in json format
  • ?q=Dockerfile: 搜索目录中与 Dockerfile 匹配的文件,类似于 find -name Dockerfile。
  • ?simple: 只输出文件或文件夹的名称,类似于 ls -1。
  • ?json: 以 JSON 格式输出目录内容。
  1. 授权访问
curl http://127.0.0.1:5000/file --user user:pass                 # basic auth
curl http://127.0.0.1:5000/file --user user:pass --digest        # digest auth
  • –user user:pass: 使用基本验证,提供用户名 user 和密码 pass 进行身份验证。
  • –digest: 使用摘要认证(Digest Authentication),这是更安全的一种认证方式。
  1. 断点续传下载
curl -C- -o file http://127.0.0.1:5000/file
  • -C-: 断点续传下载,自动从上次中断处恢复下载。
  • -o file: 将下载的文件保存为指定名称。

10.支持断点续传的上传 (Resumable uploads)

upload_offset=$(curl -I -s http://127.0.0.1:5000/file | tr -d '\r' | sed -n 's/content-length: //p')
dd skip=$upload_offset if=file status=none ibs=1 | \
  curl -X PATCH -H "X-Update-Range: append" --data-binary @- http://127.0.0.1:5000/file
  • 第一行: 获取已上传的文件大小,作为断点续传的起点。
    • -I: 获取文件的头信息(header)。
    • tr -d ‘\r’: 删除回车符。
    • sed -n ‘s/content-length: //p’: 提取 Content-Length 头的值,表示已上传的字节数。
  • 第二行: 从断点处继续上传文件。
    • dd skip=$upload_offset if=file status=none ibs=1: 跳过已上传的部分,从断点处开始读取文件。
    • curl -X PATCH -H “X-Update-Range: append” --data-binary @-: 使用 PATCH 方法上传文件剩余部分。
  • 18
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

huhy~

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值