BeagleBone Black 之 TFTP 的搭建配置

TFTP: Trivial File Transport Protocol

TFTP 是一种简单的文件传输协议,通过UDP(User Datagram Protocol)的端口号69 来实现。TFTP 缺少很多正规的FTP的特征,主要是为小型和易于实现而设计的。TFTP仅仅读写文件到远程服务器,或从远端服务器读写文件。它无法列出目录,且不提供用户授权。因此安全性匮乏,主要用于私人本地文件传输。


xinted: eXtended InterNET Deamon

BeagleBone Black 之 TFTP 的搭建配置_第1张图片

上图可以看到左图的个服务都要自己的守护进程,来监听和处理对应端口号进来的请求;右图则有xinetd一个守护进程来监听各种端口的请求,并加载相应的服务进行处理这些请求,起到代理的作用,从而可以有效提高系统的性能;有些例外如,SMTP服务器,用于传递e-mail ,一般要求拥有自己独立的进程


ubuntu host 端 TFTP服务器搭建:

1. 安装xinetd daemon 、tftp客户端, tftpd服务器

$ sudo apt-get install xinetd tftp tftpd

2. 配置tftp,通过xinetd daemon 来实现监听

$ cd /etc/xinetd.d  

$ sudo gedit  tftp 

   写入如下内容,并保存

service tftp {
   protocol = udp
   port = 69
   socket_type = dgram
   wait = yes
   user = nobody
   server = /usr/sbin/in.tftpd 
   server_args = "-s $tftproot"
   disable = no
}
3. 建立tftp的根目录

$ sudo mkdir /tftpboot

$ chmod 777 /tftpboot

4. 重载xinet.d daemon

$ sudo /etc/init.d/xinetd reload

5. 在主机上测试tftp,首先在/tftpboot目录任意建个文件

$ cd /tftpboot

$ touch test

 选择要加载目,执行相应操作命令

$ cd ~

$ tftp localhost

$ tftp > get test

 配置正确,在“~”目录下就可以找到刚建立的“test”文件了。


BBBlack 客户端操作

1. BBB的angstorm 系统已经装好 BusyBox的tftp命令,以下是命令格式

用法: tftp [OPTIONS] HOST [PORT]

传输文件来(或去)tftp 服务器

Options:

        -l FILE 本地文件
        -r FILE 远端文件
        -g      下载文件
        -p      上传文件
        

2. 在BBB terminal 上,下载文件“test”

# tftp -g -r  test 192.168.7.1

也可以这样,加上端口号

# tftp -g -r test 192.168.7.1:69

3. 修改“test”文件,上传

#tftp -p -l test 192.168.7.1

注意:上传的文件仅限制在服务器目录下,具有读写权限的同名文件,否则会如下错误提示

tftp: server error: (2) Access violation 

备注:192.168.7.1 为ubuntu host 端的ipaddress;

另附一份shell的安装命令脚本:tftp_setup.sh

#!/bin/bash
# author: wiwa
# date:20140613
# revision:01
# The document has referenced TI relative setup files.
revision="revison_01"


echo "The TFTP setup $revision  will be touch now...."
packages2install="tftpd xinetd tftp tftpd"
cmd="sudo apt-get install"

check_status() {	
	status=$?
	if [ "$status" != "0" ]; then
		echo "Sorry Failed setup"
		exit 1
	else 
		echo -e "Good Jobs"
	fi
}

entry_header() {
cat << EOF
-------------------------------------------------------------------------------
Welcome TFTP server setup Interface:^_^
-------------------------------------------------------------------------------
EOF
}

stage2_install() {
cat << EOF
-------------------------------------------------------------------------------
We now step into stage2 phase:^_^
-------------------------------------------------------------------------------
EOF
}

exit_footer() {
cat << EOF
-------------------------------------------------------------------------------
OK OK here , see you :^_^
-------------------------------------------------------------------------------
EOF
}

# Program  start
entry_header

# check the missing packapges
for i in $packages2install; do
	is_installed=`dpkg-query -l $i 2>/dev/null`
	if [ "$?" != "0" ]; then
		needs_install=`echo $needs_instal`" "$i
		new_cmd=`echo $cmd`" "$i
		cmd=$new_cmd
	fi
done

if [ "$needs_install" = "" ]; then
	echo "System has all required packages"
else
	echo "The requires packages:$needs_install to be installed"
	echo "Installation requires administrator priviliges"
	echo "on your host. Do you wiil authorize it?"

	# Force the user to answer.may be you want to exit
	while true;
	do 
		read -p "Type 'y' to continue or 'n' to abort:  " yn
		[ "$yn" == "Y" -o "$yn" == "y" -o "$yn" == "N" -o "$yn" == "n" ] && break;
 	done
	
	if [ "$yn" = 'n' -o "$yn" = 'N' ]; then
		echo "Abort now... Thanks"
		exit
	fi

	echo "Performing $cmd"
	$cmd
	check_status
fi


# enter into stage 2
stage2_install
tftprootdefault="/tftpboot"
tftpcfg=/etc/xinetd.d/tftp
tftp() {
    echo "
service tftp
{
protocol = udp
port = 69
socket_type = dgram
wait = yes
user = nobody
server = /usr/sbin/in.tftpd 
server_args = "-s $tftproot"
disable = no
}
" | sudo tee /etc/xinetd.d/tftp > /dev/null
}

echo "choose the directory you want to be tftp root directory"
read -p "[ $tftprootdefault"] tftproot

if [ "" == "$tftproot" ]; then
	tftproot=$tftprootdefault
fi
echo "Now will set up the tftp server in the $tftproot directory."

if  [ -d $tftproot ]; then
	echo 
	echo "The $tftproot exists, quit.."
else 
	sudo mkdir -p $tftproot
	check_status
	sudo chmod 777 $tftproot
	check_status
	sudo chown nobody $tftproot
	check_status
fi


if [ -n "$tftpcfg" ]; then 		
	if [ -f $tftpcfg  ]; then
		#Use = instead of == for POSIX and dash shell compliance
		if [ "`cat $tftpcfg | grep args | cut -d = -f2 | sed 's/^[ ]*//'`" \
		      = " $tftproot" ]; then
		    echo "$tftproot already exported for TFTP, skipping.."
		else
	  	    echo "Copying old $tftpcfg to $tftpcfg.old"
		    sudo cp $tftpcfg $tftpcfg.old
		    check_status
		    tftp
		fi
	else
		tftp
	fi
else 
	exit 1;
fi

echo
echo "reload the tftp server..."
echo /etc/init.d/xinetd reload
check_status
sleep 1
echo "Finish the TFTP server configure."


# Print the exit statement to the console
exit_footer


参考资料列表:

wikipedia:Trivial File Transfer Protocol

配置TFTP服务器:Configuring a TFTP Server for Linux

inted 和 xinetd 介绍:http://www.ibm.com/developerworks/aix/library/au-spunix-inetd/index.html

[BusyBox] tftp usage for newbie


   

你可能感兴趣的:(Beaglebone,Black)