LinuxCommandLibrary

tftp

Transfer files via Trivial File Transfer Protocol

TLDR

Connect to a TFTP server specifying its IP address and port

$ tftp [server_ip] [port]
copy

Connect to a TFTP server and execute a TFTP [c]ommand
$ tftp [server_ip] -c [command]
copy

Connect to a TFTP server using IPv6 and force originating port to be in [R]ange
$ tftp [server_ip] -6 -R [port]:[port]
copy

Set the transfer mode to binary or ASCIi through the tftp client
$ mode [binary|ascii]
copy

Download file from a server through the tftp client
$ get [file]
copy

Upload file to a server through the tftp client
$ put [file]
copy

Exit the tftp client
$ quit
copy

SYNOPSIS

tftp [options] [host [port]]
tftp -g|-p [options] remote-file [local-file]

PARAMETERS

host
    The hostname or IP address of the remote TFTP server to connect to. Required for non-interactive transfers.

port
    The remote UDP port number to connect to. Defaults to 69.

-g remote-file / --get remote-file
    Performs a non-interactive 'get' (download) operation for the specified remote-file. An optional local-file can be specified as the destination.

-p local-file / --put local-file
    Performs a non-interactive 'put' (upload) operation for the specified local-file. An optional remote-file can be specified as the destination on the server.

-c command / --command command
    Executes a single TFTP command (e.g., 'get file', 'put file', 'mode octet') non-interactively, then exits the client.

-l port / --local-port port
    Specifies the local UDP port to bind to for the transfer.

-m mode / --mode mode
    Sets the transfer mode for file transfers. Common modes are 'netascii' (for text files) and 'octet' (for binary files, which is the default).

-r port / --remote-port port
    Specifies the remote UDP port on the TFTP server to connect to.

-v / --verbose
    Enables verbose output, showing more details about the transfer process, including packet information.

-R count / --retries count
    Sets the maximum number of retransmission count for lost packets before giving up.

-t seconds / --timeout seconds
    Sets the timeout in seconds to wait for an acknowledgment before retransmitting a packet.

-b size / --blocksize size
    Sets the TFTP 'blksize' option to the specified size (in bytes), allowing negotiation of larger data blocks per packet.

-B / --blksize-option
    Explicitly enables the TFTP 'blksize' option, allowing the negotiation of larger transfer block sizes.

-k / --tsize-option
    Enables the TFTP 'tsize' (transfer size) option, allowing the client to query or specify the file size before transfer begins.

-N / --no-tftp-options
    Disables all TFTP options (e.g., blksize, tsize) during the transfer, forcing basic TFTP behavior.

-h / --help
    Displays a brief help message with command-line options and exits.

-V / --version
    Displays the version information for the tftp client and exits.

DESCRIPTION

The tftp command is a client for the Trivial File Transfer Protocol (TFTP), a very simple protocol for transferring files. Unlike FTP, TFTP uses User Datagram Protocol (UDP) for transport, lacks user authentication and encryption, and is connectionless. This design makes it ideal for specific tasks such as booting diskless workstations, network devices (e.g., routers, switches), and firmware updates where simplicity and minimal overhead are crucial, and security is handled by network segmentation or physical access control.

The tftp command can operate in two primary modes: a non-interactive mode for direct file transfer using command-line arguments, or an interactive mode where users can issue multiple commands within a TFTP session. It typically communicates on UDP port 69, though other ports can be specified.

CAVEATS

TFTP inherently lacks security features such as user authentication, encryption, and directory listing. All transfers are in plain text and are vulnerable to eavesdropping, spoofing, and unauthorized access if the network is not secure. Being UDP-based, it is connectionless and does not guarantee delivery, though tftp clients implement retransmission logic to handle packet loss. Due to its simplicity and security limitations, it is generally not suitable for transferring large files or sensitive data in untrusted environments. Proper firewall rules (UDP port 69) and server-side file permissions are critical for controlling access and ensuring security.

INTERACTIVE MODE

When tftp is invoked without the -g, -p, or -c options (and optionally without a host), it enters an interactive mode. In this mode, users can issue multiple commands to control the TFTP session, making it suitable for multiple transfers or changing parameters on the fly. To connect to a server, use the connect command. Below are some common interactive commands:

  • connect host [port]: Sets the remote host and optional port for subsequent transfers.
  • mode {netascii|octet|mail}: Sets the file transfer mode for future get or put operations.
  • get remote-file [local-file]: Downloads remote-file from the server. If local-file is omitted, it defaults to the remote-file name.
  • put local-file [remote-file]: Uploads local-file to the server. If remote-file is omitted, it defaults to the local-file name.
  • verbose: Toggles verbose output for command execution and transfer details.
  • trace: Toggles packet tracing, showing the details of each TFTP packet sent and received, useful for debugging.
  • status: Displays the current state of the tftp client, including the current remote host, port, and transfer mode.
  • quit or exit: Exits the interactive tftp session.

HISTORY

The Trivial File Transfer Protocol (TFTP) was defined in RFC 783 in June 1981, making it one of the earliest Internet protocols. Its design prioritized simplicity and a small code footprint, making it ideal for bootstrapping operations (like network booting) where a full-featured TCP/IP stack was not yet available or practical (e.g., ROM-based bootloaders). While less common for general-purpose file transfer today due to its inherent security limitations, TFTP remains a standard and crucial component in specific embedded systems, network device configuration, and PXE (Preboot Execution Environment) boot environments.

SEE ALSO

ftp(1), sftp(1), scp(1), nc(1), atftpd(8), in.tftpd(8)

Copied to clipboard