foyou-http
零依赖、界面现代的 HTTP 文件服务器。一条命令把任意目录共享到局域网,在浏览器里浏览、预览、上传、下载和管理文件。
- 零依赖:只用 Python 标准库,
pip install秒装,Python 3.9+ 即可运行 - 现代界面:列表 / 网格视图、深色模式、移动端适配、无刷新跳转
- 在线预览:图片、视频、音频、PDF、文本与代码(自动识别 UTF-8 / GBK),键盘 ← → 切换
- 上传:多文件、整个文件夹、拖拽上传(可直接拖到子文件夹上),实时进度、速度、可取消,重名自动改名
- 下载:断点续传(Range)、缓存校验(ETag / 304),文件夹或多选项打包成 zip 流式下载
- 管理:新建文件夹、重命名、删除、批量操作、复制链接、右键菜单、快捷键
- HTTPS:
--https一键开启,纯 Python 生成并复用自签名证书(无需 openssl),也可以用自己的证书 - 安全:路径穿越防护、跨站提交拦截、Basic 认证、只读模式、上传大小限制;重命名和删除需显式开启
安装
pip install -U foyou-http
# 或使用 pipx 安装为独立命令
pipx install foyou-http
使用
foyou-http # 共享当前目录,默认端口 5512
foyou-http ~/Downloads -p 8000 # 指定目录和端口
foyou-http -r # 只读共享
foyou-http -d -a admin:123456 # 允许重命名/删除,并开启密码
foyou-http --https # 使用自签名证书开启 HTTPS
python -m foyou.http # 不安装命令也可以这样运行
启动后终端会显示本机和局域网访问地址:
foyou-http 0.2.0 已启动
共享目录 /home/me/share
本机访问 http://127.0.0.1:5512/
局域网 http://192.168.1.23:5512/
权限 浏览/下载 · 上传/新建
认证 未开启
命令行参数
| 参数 | 说明 |
|---|---|
dir |
共享目录,默认当前目录 |
-H, --host |
监听地址,默认 0.0.0.0(所有网卡);只给本机用可设为 127.0.0.1 |
-p, --port |
监听端口,默认 5512;0 表示随机端口 |
-r, --readonly |
只读模式,禁止上传、新建、重命名、删除 |
-d, --allow-delete |
允许重命名和删除(默认关闭) |
-a, --auth USER:PASS |
开启 HTTP Basic 认证;也可以用环境变量 FOYOU_HTTP_AUTH,避免密码出现在进程列表里 |
--max-size SIZE |
单次上传大小上限,如 500M、2G |
--show-hidden |
显示并允许访问隐藏文件(. 开头,或 Windows 隐藏属性) |
--cors |
允许跨域访问 |
-s, --https |
启用 HTTPS,自动生成并复用自签名证书 |
--cert FILE |
使用自己的 PEM 证书(隐含 --https),可以是完整证书链 |
--key FILE |
--cert 对应的私钥;私钥和证书在同一文件中时可省略 |
-o, --open |
启动后自动打开浏览器 |
-q, --quiet |
不输出访问日志 |
-v, --version |
显示版本 |
快捷键
| 按键 | 作用 |
|---|---|
/ 或 Ctrl+F |
搜索当前目录 |
Backspace / Alt+↑ |
返回上一级 |
Ctrl+A |
全选 |
Ctrl + 点击、Shift + 点击 |
多选、连续选择 |
Delete / F2 |
删除 / 重命名选中项(需 --allow-delete) |
← → Esc |
预览时切换、关闭 |
HTTPS
foyou-http --https # 自签名证书
foyou-http --cert fullchain.pem --key privkey.pem # 自己的证书(如 Let's Encrypt、mkcert)
使用 --https 时,foyou-http 会用纯 Python 生成一张 ECDSA P-256 自签名证书,覆盖 localhost、127.0.0.1、::1、本机主机名和当前局域网 IP,有效期 825 天,并缓存起来重复使用:
| 系统 | 证书目录 |
|---|---|
| Windows | %LOCALAPPDATA%\foyou-http\ |
| macOS | ~/Library/Application Support/foyou-http/ |
| Linux | $XDG_CONFIG_HOME/foyou-http/(默认 ~/.config/foyou-http/) |
可以用环境变量 FOYOU_HTTP_CERT_DIR 指定其他目录。证书快过期,或者换到新网络、出现证书里没有的 IP 时,会自动重新生成(保留原有地址);删除该目录即可强制重新生成。
- 自签名证书不受浏览器信任,首次访问会提示“连接不是私密连接”,核对启动时打印的 SHA-256 指纹后选择继续访问即可。
- 想彻底消除警告,可以把
cert.pem导入系统或浏览器的受信任根证书,或者用 mkcert 签发证书后通过--cert/--key使用。 - 用
http://访问 HTTPS 端口会自动跳转到https://。 - 开启 HTTPS 后页面处于安全上下文,局域网访问时“复制链接”等依赖剪贴板的功能也能正常使用。
命令行 / 脚本访问
# 下载(支持断点续传)
curl -O -C - http://host:5512/path/file.iso
# 上传到某个目录(可一次上传多个)
curl -F files=@a.txt -F files=@b.jpg http://host:5512/path/
# 获取目录列表 JSON
curl http://host:5512/path/?json
# 把整个目录打包下载
curl -o backup.zip "http://host:5512/path/?zip"
管理接口(JSON,POST):
| 接口 | 请求体 | 权限 |
|---|---|---|
/__foyou_http__/api/mkdir |
{"path": "/dir/", "name": "新文件夹"} |
上传 |
/__foyou_http__/api/rename |
{"path": "/dir/old.txt", "name": "new.txt"} |
--allow-delete |
/__foyou_http__/api/delete |
{"paths": ["/dir/a.txt", "/dir/b/"]} |
--allow-delete |
安全提示
foyou-http 面向局域网内的临时文件共享。默认监听所有网卡,同一网络中的人都能访问,并且可以上传文件。在不受信任的网络中,请使用 --auth 设置密码,或用 -r 只读共享。Basic 认证在 HTTP 下是明文传输,建议同时加上 --https;如果需要在公网长期使用,推荐使用正式证书(--cert)或在前面加一层反向代理(如 Caddy、Nginx)。
开发
python -m venv .venv
.venv/bin/pip install -e ".[test]" # Windows: .venv\Scripts\pip
.venv/bin/pytest
项目结构:
src/foyou/http/
├── cli.py 命令行参数与启动输出
├── server.py HTTP 服务:路由、下载、上传、zip、管理接口、TLS 接入
├── fsutil.py 路径解析、隐藏文件判断、安全文件名
├── multipart.py 流式 multipart/form-data 解析
├── tls.py HTTPS:自签名证书缓存、SSLContext
├── certgen.py 纯 Python 生成 ECDSA P-256 自签名证书
├── netutil.py 局域网地址探测等网络工具
└── assets/ 前端页面(index.html、app.js、app.css、图标)
scripts/make_icons.py 重新生成图标
tests/ pytest 测试
发布:推送 vX.Y.Z 标签后,GitHub Actions 会跑测试、把版本号写入 __init__.py、构建并发布到 PyPI 和 GitHub Release。
许可证
GPL-3.0-or-later
Metadata
Release files for foyou-http 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| foyou_http-0.2.0.tar.gz | 82.7 kB | Without provenance | Details for foyou_http-0.2.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| foyou_http-0.2.0-py3-none-any.whl | Python 3 | none | any | Details for foyou_http-0.2.0-py3-none-any.whl |
Total release size: 158.1 kB
Release files / foyou_http-0.2.0.tar.gz
| Download URL | foyou_http-0.2.0.tar.gz |
|---|---|
| Size | 82.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
3f923907ab0f141aa53897521b825b6375ba52d6e1cdcc99ddbcc13c6ead4e29
|
|
BLAKE2b-256 checksum How to use checksums |
62988bf13261ab871d2e69987eb20c5920e31d3a591fab2e82c569d70c5dc28f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Release files / foyou_http-0.2.0-py3-none-any.whl
| Download URL | foyou_http-0.2.0-py3-none-any.whl |
|---|---|
| Size | 75.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
870d9fa0697c7afca21ae4bf069ad0c8c9f2470af32edd377378f1b5793f1b76
|
|
BLAKE2b-256 checksum How to use checksums |
b67f3640895b43af324e5344071dad3f3b5c5a3d64f2c4dab4c6d3a8acc9365b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Security for foyou-http 0.2.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.