# 配置启用macOS自带TFTP Server服务

`TFTP`（`Trivial File Transfer Protocol`,简单文件传输协议）是一个基于`UDP`协议的简单的、低开销的文件传输协议。使用端口号为`69`。`TFTP`常用于小容量存储的服务器，如路由器等。

macOS默认安装了`TFTP`但默认未启用，下面我们来看如何配置启用macOS自带`TFTP Server`。

## 1. 配置TFTP
### 1.1 删除节点
Mac自带`TFTP`配置文件为`/System/Library/LaunchDaemons/tftp.plist`，打开配置文件删除以下内容：
```
<key>Disabled</key>
<true/>
```

### 1.2 修改默认配置(可选)
配置文件以下配置,可按需修改。
```xml
<array>
    <string>/usr/libexec/tftpd</string>
    <string>-i</string>
    <string>-l</string>
    <string>/private/tftpboot</string>
</array>
```
* `-i` 表示开启不安全模式
* `-l` 表示使用`syslog`记录所有请求的日志
* `/private/tftpboot` 则是默认共享目录

```bash
sudo launchctl load -F /System/Library/LaunchDaemons/tftp.plist
```

### 1.3 修改共享目录权限
共享目录设置完成需要确保其有读写权限。
```bash
chmod -R 777 /private/tftpboot
```
## 2. 启动关闭TFTP
```bash
# 启动tftp
sudo launchctl load -F /System/Library/LaunchDaemons/tftp.plist
sudo launchctl start com.apple.tftpd
 
# 关闭tftp
sudo launchctl unload -F /System/Library/LaunchDaemons/tftp.plist
sudo launchctl stop com.apple.tftpd
```
启动成功后可以在终端中连接服务进行测试。

![开关TFTP](https://cdn.hashnode.com/res/hashnode/image/upload/v1658738487408/C5h7olYHl.jpg align="left")

**在上传文件之前，在服务器端要求文件必须已存在并有读写权限。**
```bash
sudo touch /private/tftpboot/running-config
sudo chmod 777 /private/tftpboot/running-config
```
