TFTP(Trivial File Transfer Protocol)即简单文件传输协议,是TCP/IP协议族中的一个用来在客户机与服务器之间进行简单文件传输的协议,提供不复杂、开销不大的文件传输服务,端口号为69。
Ubuntu和开发板之间用TFTP协议传输文件时,Ubuntu为TFTP服务器,开发板为客户端 。
1、检查是否安装TFTP服务器
$ dpkg -s tftpd-hpa
如果显示如下信息,则表示未安装:
dpkg-query: package 'tftpd-hpa' is not installed and no information is available
Use dpkg --info (= dpkg-deb --info) to examine archive files.
2、安装TFTP服务器,前提是确保Ubuntu能正常访问外网
$ sudo apt-get update
$ sudo apt-get upgrade
$ sudo apt-get install tftpd-hpa tftp-hpa
再执行步骤一的命令,如显示如下,则代表安装完成:
Package: tftpd-hpa
Status: install ok installed
Priority: optional
Section: net
Installed-Size: 113
Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com>
Architecture: amd64
Source: tftp-hpa
Version: 5.2+20150808-1.4build1
Replaces: atftpd, tftp-server, tftpd
Provides: tftp-server
Depends: libc6 (>= 2.38), libwrap0 (>= 7.6-4~), adduser, debconf (>= 0.5) | debconf-2.0
Suggests: pxelinux
Conflicts: atftpd, tftp-server, tftpd
Conffiles:
/etc/init.d/tftpd-hpa 6be1795d3a8f511fce8ea16cb04a34a0
/etc/init/tftpd-hpa.conf 3cbc30e20e9dfc201999978cddb03170
Description: HPA's tftp server
Trivial File Transfer Protocol (TFTP) is a file transfer protocol, mainly to
serve boot images over the network to other machines (PXE).
.
tftp-hpa is an enhanced version of the BSD TFTP client and server. It
possesses a number of bugfixes and enhancements over the original.
.
This package contains the server.
Homepage: http://git.kernel.org/cgit/network/tftp/tftp-hpa.git
Original-Maintainer: Ron Lee <ron@debian.org>
3、修改TFTP配置文件
执行以下代码,打开配置文件:
$ sudo vi /etc/default/tftpd-hpa
将内容更新为:
注:TFTP_DIRECTORY 是 tftp 服务器的工作目录,即客户端要下载的文件需要放到该目录下.
4、创建服务器工作目录并设置为最高的权限
$ sudo mkdir /tftpboot
$ sudo chmod 777 /tftpboot
5、重启 tftp 服务,使配置生效
$ sudo service tftpd-hpa restart
注:以后每次重新打开
ubuntu,
若要使用
tftp
都需要重启,如果不能使用tftp,很可能是没有重启。
6、本地测试是否配置成功
首先cd到tftpboot目录,touch一个测试文件test.txt,再cd到家目录
$ cd /tftpboot/
$ sudo touch test.txt
$ cd
使用tftp命令登录本机,并用get命令获取test.txt文件,最后输入q退出,最后执行ls命令,看是否能在当前目录下看到test.txt文件,如果能看到,则代表测试成功:
$ tftp localhost
tftp> get test.txt
tftp> q
$ ls