基于MT7688模块的开发笔记10——通过TFTP实现Ubuntu与开发板之间的文件传输

本篇文章是上一篇文章的继续,在这篇文章里我通过在Ubuntu上搭建TFTP服务器,实现了在MT7688开发板上上传和下载Ubuntu中的文件,这为后面的程序开发提供了方便。

一、安装TFTP服务器:安装tftp-hpa和tftpd-hpa软件

1.1安装第一个软件

root@openwrt:/home# apt-get install tftp-hpa
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following NEW packages will be installed:
  tftp-hpa
0 upgraded, 1 newly installed, 0 to remove and 523 not upgraded.
Need to get 19.1 kB of archives.
After this operation, 75.8 kB of additional disk space will be used.
WARNING: The following packages cannot be authenticated!
  tftp-hpa
Install these packages without verification [y/N]? Y
Get:1 http://us.archive.ubuntu.com/ubuntu/ precise/main tftp-hpa i386 5.2-1ubuntu1 [19.1 kB]
Fetched 19.1 kB in 2s (7,362 B/s)
Selecting previously unselected package tftp-hpa.
(Reading database ... 150828 files and directories currently installed.)
Unpacking tftp-hpa (from .../tftp-hpa_5.2-1ubuntu1_i386.deb) ...
Processing triggers for man-db ...
Setting up tftp-hpa (5.2-1ubuntu1) ...

1.2安装第二个软件
root@openwrt:/home# apt-get install tftpd-hpa
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following NEW packages will be installed:
  tftpd-hpa
0 upgraded, 1 newly installed, 0 to remove and 523 not upgraded.
Need to get 39.4 kB of archives.
After this operation, 140 kB of additional disk space will be used.
WARNING: The following packages cannot be authenticated!
  tftpd-hpa
Install these packages without verification [y/N]? y
Get:1 http://us.archive.ubuntu.com/ubuntu/ precise/main tftpd-hpa i386 5.2-1ubuntu1 [39.4 kB]
Fetched 39.4 kB in 0s (45.5 kB/s)
Preconfiguring packages ...
Selecting previously unselected package tftpd-hpa.
(Reading database ... 150834 files and directories currently installed.)
Unpacking tftpd-hpa (from .../tftpd-hpa_5.2-1ubuntu1_i386.deb) ...
Processing triggers for man-db ...
Processing triggers for ureadahead ...
ureadahead will be reprofiled on next reboot
Setting up tftpd-hpa (5.2-1ubuntu1) ...
tftpd-hpa start/running, process 3770


二、在home目录下建立shareFiles文件夹,更改文件夹的权限,创建test.txt文件,写入文件内容。
root@openwrt:/home# dir
MT7688Share  openwrt  shareFiles
root@openwrt:/home# cd shareFiles/
root@openwrt:/home/shareFiles# ls
test.txt
root@openwrt:/home/shareFiles# cat test.txt
This is a test file in Unbuntu. It is mainly used as the tftp test file!


三、修改配置文件
root@openwrt:/home/shareFiles# ls
test.txt
root@openwrt:/home/shareFiles# vim /etc/default/tftpd-hpa
root@openwrt:/home/shareFiles#
配置内容如下:192.168.1.107为我的Ubuntu系统的IP地址
# /etc/default/tftpd-hpa
TFTP_USERNAME="tftp"
TFTP_DIRECTORY="/home/shareFiles"
TFTP_ADDRESS="192.168.1.107:69"

TFTP_OPTIONS="-l -c -s"


四、启动服务
root@openwrt:/home/shareFiles# service tftpd-hpa restart
tftpd-hpa stop/waiting
tftpd-hpa start/running, process 3933
root@openwrt:/home/shareFiles# ps -au | grep tftpd-hpa
Warning: bad ps syntax, perhaps a bogus '-'? See http://procps.sf.net/faq.html
root      3959  0.0  0.0   4388   832 pts/2    S+   01:36   0:00 grep --color=auto tftpd-hpa

root@openwrt:/home/shareFiles#


五、测试
这里说明一下:下面的IP地址为TFTP服务器的地址,以下两个命令在开发板上使用,你首先Telnet到开发板即可
tftp -g -r file ip//从TFTP下载文件
tftp -p -l file ip//向TFTP上传文件


5.1在Ubuntu系统TFTP服务器的共享目录上创建一个test.txt的测试文件,可以简单在文件中写入一些内容
root@openwrt:/home/shareFiles# ls
hello  test.txt
root@openwrt:/home/shareFiles# cat test.txt
This is a test file in Ubuntu

root@openwrt:/home/shareFiles#


5.2在Unbuntu中通过Telnet方式登录MT7688开发板,尝试下载TFTP中的文件
root@openwrt:/home/shareFiles# telnet 192.168.1.1
Trying 192.168.1.1...
Connected to 192.168.1.1.
Escape character is '^]'.
Mediatek login: admin
Password:
BusyBox v1.12.1 (2015-07-14 09:33:29 CST) built-in shell (ash)
Enter 'help' for a list of built-in commands.
# tftp -g -r test.txt 192.168.1.100
# ls
etc       bin       init      media     etc_ro    test.txt
home      mnt       var       dev       tmp
sys       proc      usr       sbin      lib
# cat test.txt
This is a test file in Ubuntu

下载成功,而且可以正确查看该文件!


5.2测试将MT7688开发板上的文件上传到Ubuntu:我在MT7688上创建了123.txt文件
现在处于MT7688开发板上:
# ls
etc       bin       init      media     etc_ro    test.txt
home      mnt       var       dev       tmp
sys       proc      usr       sbin      lib
# touch 123.txt
# echo "This is a test file in MT7688" >> 123.txt
# cat 123.txt
This is a test file in MT7688
# tftp -p -l 123.txt 192.168.1.100
# exit
现在处于Ubuntu系统上:
root@openwrt:/home/shareFiles# pwd
/home/shareFiles
root@openwrt:/home/shareFiles# ls
123.txt  hello  test.txt
root@openwrt:/home/shareFiles# cat 123.txt
This is a test file in MT7688
root@openwrt:/home/shareFiles#


成功!综上测试,我们已经实现了通过tftp服务在Ubuntu系统与MT7688开发板之间实现文件的互传!有了这个功能就方便我们把Ubuntu系统编写的程序放到开发板上运行!

















你可能感兴趣的:(linux,ubuntu,TFTP,文件传输,openwrt)