tftp

Use TFTP protocol to transfer files between the local machine and tftp server

Supplementary instructions

tftp command is used to transfer files between the local machine and the tftp server using the TFTP protocol.

TFTP is the simplest network protocol used to download remote files. It is implemented on the UDP protocol. The tftp development environment of embedded Linux includes two aspects: one is the tftp-server support of the Linux server, and the other is the tftp-client support of the embedded target system. Because u-boot itself has built-in support for tftp-client, there is no need to configure the embedded target system. The following will introduce the configuration of tftp-server on the Linux server side in detail.

grammar

tftp(options)(parameters)

Options

-c: Specify the command to be executed immediately after successfully connecting to the tftp server;
-m: Specifies the file transfer mode. Can be ASCII or Binary;
-v: Display the detailed execution process of the command;
-V: Display command version information.

Parameters

Host: Specify the IP address or host name of the tftp server to which tftp will connect.

Example

1. Install tftp server

3 softwares, xinetd, tftp and tftp-server, need to be installed.

If you have access to the Internet, install it through yum:

yum install xinetd
yum install tftp
yum install tftp-server

If you cannot access the Internet, you can directly install the provided rpm package:

rpm -ivh xinetd-2.3.14-18.fc9.i386.rpm
rpm -ivh tftp-0.48-3.fc9.i386.rpm
rpm -ivh tftp-server-0.48-3.fc9.i386.rpm

2. Configure tftp server

Modify the /etc/xinetd.d/tftp file and change disable=yes to disable=no. The main thing is to set the root directory of the TFTP server and start the service. The modified file is as follows:

servicetftp
{
        socket_type =dgram
        protocol=udp
        wait=yes
        user=root
        server =/usr/sbin/in.tftpd
        server_args =-s /home/mike/tftpboot -c
        disable=no
        per_source =11
        cps =100 2
        flags=IPv4
}

Note: Modify the item server_args= -s <path> -c, where can be changed to the root directory of your tftp-server, the parameter -s specifies chroot, and -c specifies that files can be created.

3. Start the tftp server and turn off the firewall

/etc/init.d/iptables stop # Turn off the firewall
sudo /sbin/service xinetd start
or
service xinetd restart
/etc/init.d/xinetd start

Just see startup [OK]

netstat -a | grep tftp

The displayed result is udp 0 0 *:tftp *:*, which indicates that the service has been started, which means that the tftp configuration is successful.

5. Use of tftp

Copy a file to the tftp server directory, then start the tftp software on the host for a simple test.

tftp 192.168.1.2
tftp>get <download file>

tftp>put <upload file>
tftp>q

6. The usage of tftp command is as follows

tftp your-ip-address

Enter TFTP operation:

7. If the error "AVC Denial, click icon to view" always occurs and the file cannot be transferred, you need to make the following modifications

Modify /etc/sysconfig/selinux, set SELINUX to disable, and use the command setenforce 0 to make the selinux configuration file take effect.

8. Usage of tftp command in Busybox

The command format is:

tftp [option] ... host [port]

If you want to download or upload files, you must use these options.

-g means download file (get)
-p means upload file (put)
-l means local file name (local file)
-r represents the file name of the remote host (remote file)

For example, to download embedexpert from the remote host 192.168.1.2, you would enter the following command

tftp -g -r embedexpert 192.168.1.2