歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> Linux技術 >> 基於MT7688模塊的開發筆記10——通過TFTP實現Ubuntu與開發板之間的文件傳輸

基於MT7688模塊的開發筆記10——通過TFTP實現Ubuntu與開發板之間的文件傳輸

日期:2017/3/3 13:00:05   编辑:Linux技術
本篇文章是上一篇文章的繼續,在這篇文章裡我通過在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:1http://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:1http://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 '-'? Seehttp://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系統編寫的程序放到開發板上運行!
Copyright © Linux教程網 All Rights Reserved