Linux tftp command

Linux 命令大全Linux Command Encyclopedia

The Linux tftp command is used to transfer files.

TFTP (Trivial File Transfer Protocol) is a simple file transfer protocol, typically used to transfer small files over a network.

Compared with FTP (File Transfer Protocol), TFTP is more lightweight and relatively simpler in function.

TFTP is commonly used in LAN environments, especially in scenarios such as firmware upgrades and configuration file transfer for network devices.

TFTP uses UDP (User Datagram Protocol) as its transport layer protocol, with a default port number of 69. Since UDP is a connectionless protocol, TFTP transfers faster but has lower reliability, so packet loss may occur during transmission.

Syntax

tftp [选项] [主机名或IP地址]

Common options:

tftpThe command supports several common options. The following are some common options and their functions:

  • -v: Enable verbose mode to display more debugging information.
  • -c: Specify the file to be transferred.
  • -l: Specify the local file name.
  • -r: Specify the remote file name.
  • -g: Get a file from the server (equivalent togetcommand).
  • -p: Upload a file to the server (equivalent toputcommand).

Operation instructions:

  • connect: Connect to a remote tftp server
  • mode: File transfer mode
  • put: Upload a file
  • get: Download a file
  • quit: Exit
  • verbose: Display detailed processing information
  • trace: Display packet path
  • status: Display current status information
  • binary: Binary transfer mode
  • ascii: ASCII transfer mode
  • rexmt: Set the timeout for packet transmission
  • timeout: Set the timeout for retransmission
  • help: Help information
  • ?: Help information

Basic usage of the TFTP command

Connect to a TFTP server

To connect to a TFTP server, use the following command:

tftp 192.168.1.1

Here,192.168.1.1is the IP address of the TFTP server. After executing this command, the system enters TFTP interactive mode and the prompt changes totftp>。

Download a file

In TFTP interactive mode, you can use thegetcommand to download a file from the server. For example, to download a file namedconfig.txt:

tftp> get config.txt

This command will download theconfig.txtfile from the TFTP server to the current working directory.

Upload a file

To upload a file to the TFTP server, use theputcommand. For example, to upload a file namedbackup.cfg:

tftp> put backup.cfg

This command will upload thebackup.cfgfile to the TFTP server.

Exit TFTP interactive mode

To exit TFTP interactive mode, use thequitorexitcommand:

tftp> quit

Examples

Connect to the remote server "218.28.188.288", then use the put command to download the file "README" from its root directory. The command is as follows:

tftp 218.28.188.288 #连接远程服务器 

After connecting to the server, you can perform the corresponding operations as follows:

$ tftp 218.28.188.228                      #连接远程服务器  
tftp> ?                                    #使用?,参考帮助  
Commands may be abbreviated. Commands are: #帮助命令列表  
connect connect to remote tftp  
mode set file transfer mode  
put send file  
get receive file  
quit exit tftp  
verbose toggle verbose mode  
trace toggle packet tracing  
status show current status  
binary set mode to octet  
ascii set mode to netascii  
rexmt set per-packet retransmission timeout  
timeout set total retransmission timeout  
? print help information  
tftp>get README                             #远程下载README文件  
getting from 218.28.188.288 to /home/cmd  
Recived 168236 bytes in 1.5 seconds[112157 bit/s]  
tftp>quit                                   #离开tftp 

Use the-voption to enable verbose mode:

tftp -v 192.168.1.1

Download a file and specify a local file name

Suppose you want to download from the TFTP server theconfig.txtfile and save it aslocal_config.txt, you can use the following command:

tftp 192.168.1.1
tftp> get config.txt local_config.txt

Upload a file and specify a remote file name

Suppose you want to upload the localbackup.cfgfile to the TFTP server and save it asremote_backup.cfg, you can use the following command:

tftp 192.168.1.1
tftp> put backup.cfg remote_backup.cfg

Download a file directly using command line options

If you do not want to enter TFTP interactive mode, you can directly use the-goption on the command line to download the file:

tftp -g -r config.txt 192.168.1.1

This command will, from192.168.1.1server, download theconfig.txtfile.


Limitations of TFTP

Although TFTP is simple and easy to use, it also has some limitations:

  • Low reliability: Because TFTP uses the UDP protocol, packet loss may occur during transmission, especially in unstable network environments.
  • Limited functionality: TFTP does not support advanced features such as directory listing and file deletion; it is only suitable for simple file transfer.
  • Low security: TFTP has no built-in encryption mechanism, so the content of transferred files may be eavesdropped on or tampered with.

Linux 命令大全Linux Command Encyclopedia

Other extensions