> For the complete documentation index, see [llms.txt](https://book.bsdcn.org/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://book.bsdcn.org/handbook/di-33-zhang-wang-luo-fu-wu-qi/33.10.-wen-jian-chuan-shu-xie-yi-ftp.md).

# 33.10.文件传输协议（FTP）

文件传输协议（FTP）为用户提供简单的方式上传和下载文件。FreeBSD 在基本系统中包含 FTP 服务器软件 ftpd。

FreeBSD 提供几个配置文件控制对 FTP 服务器的访问。本节总结这些文件的作用。更多关于内建 FTP 服务器的细节，请参考 [ftpd(8)](https://man.freebsd.org/cgi/man.cgi?query=ftpd\&sektion=8\&format=html)。

## 33.10.1. 配置

最重要的配置步骤是决定哪些账户将能访问 FTP 服务器。FreeBSD 系统有许多系统账户，这些账户不应能访问 FTP。禁止访问 FTP 的用户列表可以在 **/etc/ftpusers** 中找到。默认情况下，它包括系统账户。还可以添加其他不应能访问 FTP 的用户。

在某些情况下，可能希望限制某些用户的访问权限，而非完全禁止他们使用 FTP。创建 **/etc/ftpchroot** 即可实现，如 [ftpchroot(5)](https://man.freebsd.org/cgi/man.cgi?query=ftpchroot\&sektion=5\&format=html) 中所述。此文件列出了受到 FTP 访问限制的用户和组。

要启用匿名 FTP 访问服务器，可以在 FreeBSD 系统上创建名为 `ftp` 的用户。用户就能使用用户名 `ftp` 或 `anonymous` 登录到 FTP 服务器。提示输入密码时，任何输入都会被接受，但按惯例，密码应是电子邮件地址。匿名用户登录时，FTP 服务器将调用 [chroot(2)](https://man.freebsd.org/cgi/man.cgi?query=chroot\&sektion=2\&format=html) 限制用户的访问范围，仅限于 `ftp` 用户的主目录。

可以创建两个文本文件，指定显示给 FTP 客户端的欢迎信息。**/etc/ftpwelcome** 的内容将在用户到达登录提示符之前显示。登录成功后，将显示 **/etc/ftpmotd** 的内容。请注意，文件的路径相对于登录环境，因此匿名用户的 **\~ftp/etc/ftpmotd** 内容也将显示。

配置好 FTP 服务器后，在 **/etc/rc.conf** 中设置适当的变量，以便在引导时启动服务：

```sh
ftpd_enable="YES"
```

要立即启动服务，请执行：

```sh
# service ftpd start
```

输入以下命令测试连接到 FTP 服务器：

```sh
% ftp localhost
```

ftpd 守护进程使用 [syslog(3)](https://man.freebsd.org/cgi/man.cgi?query=syslog\&sektion=3\&format=html) 记录消息。默认情况下，系统日志守护进程将与 FTP 相关的消息写入 **/var/log/xferlog**。修改 **/etc/syslog.conf** 中的以下行即可更改 FTP 日志的位置：

```sh
ftp.info      /var/log/xferlog
```

> **注意**
>
> 请注意运行匿名 FTP 服务器可能带来的潜在问题。特别是，三思是否允许匿名用户上传文件。FTP 站点可能会变成未经授权的商业软件交易的场所，或更糟。如果需要匿名 FTP 上传，请确保权限设置正确，并保证这些文件在管理员审查之前，其他匿名用户无法读取。


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://book.bsdcn.org/handbook/di-33-zhang-wang-luo-fu-wu-qi/33.10.-wen-jian-chuan-shu-xie-yi-ftp.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
