在 Linux 上搭建 FTP 服务器时,乱码问题通常出现在文件名或目录名含有中文的情况下,尤其是 Windows 客户端访问 Linux FTP 服务器时。下面按常见场景给你一套实用解决方案。
UTF-8locale
如果不是 zh_CN.UTF-8 或 en_US.UTF-8,可设置:
sudo localectl set-locale LANG=zh_CN.UTF-8
或临时:
export LANG=zh_CN.UTF-8
编辑配置文件:
sudo vim /etc/vsftpd.conf
确保或添加:
utf8_filesystem=YES
重启服务:
sudo systemctl restart vsftpd
✅ 要求客户端支持 UTF-8(如 FileZilla)
FileZilla 支持 UTF-8,设置如下:
站点管理器 → 字符集 → 强制 UTF-8
✅ 这是最稳定、最推荐的方式
Windows 资源管理器 不支持 UTF-8 FTP,只能使用 GBK。
⚠️ 不推荐,因为会影响 Linux 本地中文显示
export LANG=zh_CN.GBK
并修改 vsftpd:
utf8_filesystem=NO
❌ 缺点:
convmv 转换文件名编码sudo apt install convmv
将 GBK 转为 UTF-8:
convmv -f gbk -t utf-8 -r --notest /ftp目录
或反向:
convmv -f utf-8 -t gbk -r --notest /ftp目录
✅ 适合存量文件乱码
编辑配置:
sudo vim /etc/proftpd/proftpd.conf
添加:
UseEncoding utf8
或指定编码:
UseEncoding utf8 gbk
重启:
sudo systemctl restart proftpd
| 客户端 | 是否推荐 | 说明 |
|---|---|---|
| FileZilla | ✅✅✅ | 支持 UTF-8 |
| WinSCP | ✅✅✅ | 支持 UTF-8 |
| Windows 资源管理器 | ❌ | 不支持 UTF-8 |
| FlashFXP | ⚠️ | 需手动设置编码 |
locale
file 文件名
ls | file -
如果看到:
ISO-8859 text, with CRLF line terminators
说明编码有问题。
✅ 最佳实践
zh_CN.UTF-8utf8_filesystem=YES如果你愿意,可以告诉我:
我可以给你精确到配置项的解决方案。