Ubuntu20 TFTP服務器的搭建和使用
TFTP (Trivial File Transfer Protocol) 是一個簡化版的FTP,適合用於簡潔的場景,比如嵌入式開發的時候向下位機傳輸文件。TFTP使用UDP協議,工作於69端口。
環境:ubuntu20 桌面版
服務器
安裝服務程序:
$ sudo apt install tftpd-hpa #客戶端程序是tftp-hpa
檢查服務運行狀態:
$ sudo systemctl status tftpd-hpa
打開配置文件
$ sudo nano /etc/default/tftpd-hpa
內容如下:
# /etc/default/tftpd-hpa
TFTP_USERNAME="tftp" #tftpd程序使用的賬戶
TFTP_DIRECTORY="/srv/tftp" #目錄
TFTP_ADDRESS=":69" #端口
TFTP_OPTIONS="--secure --create" #--secure 不設置會有跨目錄的問題 --create是要自己添加的,給客戶端寫入數據的權力
查看/srv/tftp的屬性,會發現是root的,所以:
$ sudo chown tftp:tftp /srv/tftp
重啟服務:
$ sudo systemctl restart tftpd-hpa
Busybox 的 TFTP客戶端
Busybox的tftp客戶端使用相當簡單:
BusyBox v1.31.1 (2020-07-28 18:26:21 CST) multi-call binary.
Usage: tftp [OPTIONS] HOST [PORT]
Transfer a file from/to tftp server
-l FILE Local FILE
-r FILE Remote FILE
-g Get file
-p Put file
-b SIZE Transfer blocks of SIZE octets
1、常規使用
從Server下載文件到Client時,使用下面的命令
$ tftp –g –l 目標文件名 –r 源文件名 服務器地址
example:
$ tftp –g –l B.txt –r A.txt 192.168.1.2
從Server中的tftp根目錄下,下載文件A.txt到Client並更名為B.txt.
從Clinet上傳文件到Server時,使用下面的命令
$ tftp –p –r 目標文件名 -l 源文件名 服務器地址
example:
$ tftp –p –r D.txt –l C.txt 192.168.1.2
從Client上傳文件C.txt到Server的tftp根目標下,並更名為D.txt.
2、簡略使用
不更名下載
$ tftp –g –l/-r 源文件名 服務器地址
example:
$tftp –g –l A.txt 192.168.1.2
$tftp –g –r A.txt 192.168.1.2
作用相同,都表示Client從Server下載文件A.txt,且不更名。
不更名上傳
$ tftp –p –l/-r 源文件名 服務器地址
example:
$ tftp –p –l B.txt 192.168.1.2
$ tftp -p –r B.txt 192.168.1.2
作用相同,都表示從Client上傳文件B.txt到Server,且不更名。
參考:
https://linuxhint.com/install_tftp_server_ubuntu/
https://www.networkreverse.com/2020/05/how-to-install-tftp-server-on-ubuntu-20.04.html
https://www.cnblogs.com/amanlikethis/p/6837206.html