Sen descrición

Your Name c7319a4686 feat: simplify HTTP file server to read-only mode (browse + download only) hai 3 semanas
cmd 8cfa25f0f3 feat: add HTTP file server with beautiful file browser UI hai 3 semanas
config 8cfa25f0f3 feat: add HTTP file server with beautiful file browser UI hai 3 semanas
ftp 799d814503 feat: initial FTP Server for Windows with web admin panel hai 3 semanas
httpfile c7319a4686 feat: simplify HTTP file server to read-only mode (browse + download only) hai 3 semanas
static 8cfa25f0f3 feat: add HTTP file server with beautiful file browser UI hai 3 semanas
web 8cfa25f0f3 feat: add HTTP file server with beautiful file browser UI hai 3 semanas
.gitignore 2459122c0e feat: add service start/stop scripts for Windows and Linux hai 3 semanas
NDH6SA~M c7319a4686 feat: simplify HTTP file server to read-only mode (browse + download only) hai 3 semanas
README.md e94c730def feat: add cross-platform support (Windows/Linux/macOS), update README hai 3 semanas
ftp-server.bat 2459122c0e feat: add service start/stop scripts for Windows and Linux hai 3 semanas
ftp-server.sh 2459122c0e feat: add service start/stop scripts for Windows and Linux hai 3 semanas
go.mod 799d814503 feat: initial FTP Server for Windows with web admin panel hai 3 semanas
停止FTP服务.bat 2459122c0e feat: add service start/stop scripts for Windows and Linux hai 3 semanas
启动FTP服务.bat 2459122c0e feat: add service start/stop scripts for Windows and Linux hai 3 semanas
查看FTP状态.bat 2459122c0e feat: add service start/stop scripts for Windows and Linux hai 3 semanas
重启FTP服务.bat 2459122c0e feat: add service start/stop scripts for Windows and Linux hai 3 semanas

README.md

FTP Server

基于 Go 语言开发的轻量级 FTP 服务器,带 Web 管理面板,跨平台支持 Windows / Linux / macOS

功能特性

FTP 服务

  • 完整的 FTP 协议支持(RFC 959)
  • 主动模式(PORT)和被动模式(PASV)
  • 文件上传 / 下载(STOR / RETR)
  • 目录浏览、创建、删除(LIST / MKD / RMD)
  • 文件删除、重命名(DELE / RNFR / RNTO)
  • 每用户独立的 HomeDir 和权限控制(只读 / 可写)

Web 管理面板

  • 管理员登录认证(Token 机制,24h 自动过期)
  • 仪表盘 — 服务器状态实时概览
  • 用户管理 — 添加 / 编辑 / 删除 FTP 用户
  • 系统设置 — 修改 FTP 端口、Web 端口、管理员密码

快速开始

编译

确保已安装 Go 1.21+,然后执行:

# 编译为当前平台
go build -o ftp-server ./cmd/

# 交叉编译 - Windows (64位)
GOOS=windows GOARCH=amd64 go build -o ftp-server.exe ./cmd/

# 交叉编译 - Linux (64位)
GOOS=linux GOARCH=amd64 go build -o ftp-server ./cmd/

# 交叉编译 - macOS
GOOS=darwin GOARCH=amd64 go build -o ftp-server ./cmd/

运行

Windows:

# 使用默认配置启动
.\ftp-server.exe

# 指定配置文件
.\ftp-server.exe -config myconfig.json

Linux / macOS:

# 使用默认配置启动
./ftp-server

# 指定配置文件
./ftp-server -config myconfig.json

# 后台运行
nohup ./ftp-server > ftp-server.log 2>&1 &

首次运行会自动生成 config.json 配置文件和 ftp_root 根目录。

访问

服务 地址
Web 管理面板 http://localhost:8080
FTP 服务 localhost:2121

默认账号

服务 用户名 密码
Web 管理面板 admin admin123
FTP 默认用户 ftpuser ftp123

请在首次登录后立即修改默认密码。

Linux Systemd 服务(可选)

在 Linux 上可以配置为 systemd 服务,实现开机自启:

# 创建服务文件
sudo nano /etc/systemd/system/ftp-server.service

写入以下内容(按实际路径修改):

[Unit]
Description=FTP Server
After=network.target

[Service]
Type=simple
User=root
WorkingDirectory=/opt/ftp-server
ExecStart=/opt/ftp-server/ftp-server -config /opt/ftp-server/config.json
Restart=on-failure
RestartSec=5

[Install]
WantedBy=multi-user.target

启动并设置开机自启:

sudo systemctl daemon-reload
sudo systemctl start ftp-server
sudo systemctl enable ftp-server

# 查看状态
sudo systemctl status ftp-server

# 查看日志
sudo journalctl -u ftp-server -f

配置说明

配置文件为 config.json,结构如下:

{
  "ftp": {
    "host": "0.0.0.0",
    "port": 2121,
    "passivePortMin": 50000,
    "passivePortMax": 50100,
    "rootDir": "./ftp_root"
  },
  "web": {
    "host": "0.0.0.0",
    "port": 8080
  },
  "admin": {
    "username": "admin",
    "password": "admin123"
  },
  "ftpUsers": [
    {
      "username": "ftpuser",
      "password": "ftp123",
      "homeDir": "./ftp_root",
      "write": true
    }
  ]
}
字段 说明
ftp.host FTP 监听地址
ftp.port FTP 端口(默认 2121,避免需要管理员权限)
ftp.passivePortMin/Max 被动模式端口范围
ftp.rootDir FTP 根目录
web.host Web 面板监听地址
web.port Web 面板端口
admin.username/password 管理员凭据
ftpUsers FTP 用户列表
ftpUsers[].homeDir 用户主目录
ftpUsers[].write 是否允许写入

FTP 客户端连接

推荐使用 FileZilla 连接:

主机: localhost
端口: 2121
用户名: ftpuser
密码: ftp123

项目结构

FTP-server/
├── cmd/main.go          # 主程序入口
├── config/config.go     # 配置管理模块
├── ftp/server.go        # FTP 服务核心
├── web/server.go        # Web 管理面板后端 API
├── static/embed.go      # 前端 HTML 页面(内嵌)
├── go.mod               # Go 模块定义
└── config.json          # 运行时配置(自动生成)

技术栈

  • Go — 无需运行时依赖,单文件部署,跨平台支持
  • 标准库 net/http — Web 管理面板
  • 标准库 net — FTP 协议实现
  • 内嵌 HTML/CSS/JS — 无需额外前端文件

许可证

MIT License