最近有个项目需要在服务端本地做无登录、无密码验证的文件上传与下载,TFTP最合适不过了,但在get文件时一直报
Error Code 1:File not found 。 查看了各路资料和文章,均无果,最后发现,是由于配置文件(/etc/xinetd.d/tftp)内的字符是windows格式,导致配置文件没有生效。不应发生的低级错误,记录一下,引以为戒。
环境:Centos、Redhat、Ubuntu均可
1、TFTP安装
yum -y install xinetd tftp
2、编辑配置文件
cat /etc/xinetd.d/tftp
service tftp
{
socket_type = dgram
protocol = udp
wait = yes
user = root
server = /usr/sbin/in.tftpd
server_args = -s /var/lib/tftpboot -c
disable = no
per_source = 11
cps = 100 2
flags = IPv4
}
###-s 指定目录,-c允许上传##
3、赋予权限、启服务
chmod -R 777 /var/lib/tftpboot
systemctl restart xinetd
systemctl enable xinetd
systemctl restart tftp
systemctl enable tftp
此处使用的共享目录是 /var/lib/tftpboot,可以根据实际需要在配置文件内修改。记得赋权限,否则该目录没有写权限也会报错。或者检查一下防火墙、端口、Selinux等。
TFTP使用的是UDP 69号端口
netstat -atunpl |grep 69
netstat -atunpl |grep tftp
关闭防火墙或添加端口策略
systemctl stop firewalld
iptables -A INPUT -p udp --dprot 69 -j ACCEPT
4、其他注意事项
上传的文件的路径为绝对路径时,报 “No such file or directory”。
以/etc/passwd为例,在/root下 put /etc/passwd,结果报错;
cd /etc后,put passwd,成功。
所以,尽量在文件所在的路径下进入tftp服务put文件。
以上,均为个人遇到的问题,如有差错,欢迎指正。