百搜网络科技有限公司,沈阳网站seo排名优化,做签证的网站,网络运维工程师招聘信息文件服务器 介绍安装使用命令使用API调用 介绍
项目github官网地址
Dufs是一款由Rust编写的轻量级文件服务器#xff0c;不仅支持静态文件服务#xff0c;还能轻松上传、下载、搜索文件#xff0c;甚至支持WebDAV#xff0c;让我们通过Web方式远程管理文件变得轻而易举。… 文件服务器 介绍安装使用命令使用API调用 介绍
项目github官网地址
Dufs是一款由Rust编写的轻量级文件服务器不仅支持静态文件服务还能轻松上传、下载、搜索文件甚至支持WebDAV让我们通过Web方式远程管理文件变得轻而易举。而且它跨平台无论是Windows、macOS还是Linux都能轻松驾驭
性能特色
静态文件服务一键开启让你的文件触手可及。上传下载支持拖放上传文件夹打包下载为zip省时又省力。文件操作创建、编辑、搜索文件一切尽在掌握。断点续传再也不用担心大文件传输中断了Dufs支持断点续传让你的下载上传无忧。访问控制灵活的权限设置无论是公开分享还是私密访问都能轻松搞定。HTTPS WebDAV安全传输远程管理一个都不能少。
安装使用
Ubuntu2404-server
该项目支持多平台安装这里我使用docker进行快速搭建
roothuhy:~# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
sigoden/dufs latest f7f212903ad7 3 months ago 4.37MBdocker 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目录作为共享目录
roothuhy:/home# ls
huhy sigoden.tar
roothuhy:/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/dufsUsage: 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 certificates private key-h, --help Print help-V, --version Print versionAPI调用
上传文件
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。
下载文件
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 哈希值而不是文件内容。
下载文件夹为 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 方法删除指定路径的文件或文件夹。
创建目录
curl -X MKCOL http://127.0.0.1:5000/path-to-folder-X MKCOL: 使用 MKCOL 方法创建一个新的目录。
移动文件/文件夹
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”: 指定新的路径目标路径。
列出/搜索目录内容
curl http://127.0.0.1:5000?qDockerfile # 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?qDockerfile: 搜索目录中与 Dockerfile 匹配的文件类似于 find -name Dockerfile。?simple: 只输出文件或文件夹的名称类似于 ls -1。?json: 以 JSON 格式输出目录内容。
授权访问
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这是更安全的一种认证方式。
断点续传下载
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 iffile statusnone ibs1 | \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 iffile statusnone ibs1: 跳过已上传的部分从断点处开始读取文件。curl -X PATCH -H “X-Update-Range: append” --data-binary -: 使用 PATCH 方法上传文件剩余部分。