tftp or utftp Command

Purpose

Transfers files between hosts using the Trivial File Transfer Protocol (TFTP).

Syntax

{tftp | utftp} { -g -o -p -r -w } LocalName HostPort  RemoteName [ netascii | image] [blksize #] [timeout #] [tsize]

Interactive Form Syntax

Command Line Form Syntax

Description

The /usr/bin/tftp and utftp commands transfer files between hosts using the Trivial File Transfer Protocol (TFTP). Since TFTP is a minimal file transfer protocol, the tftp and utftp commands do not provide all of the features of the ftp command. For example, the tftp and utftp commands do not provide the ability to list remote files or change directories at the remote host, and only limited file access privileges are given to the remote TFTP server. The utftp command is a form of the tftp command for use in a pipe.

The remote host must have a tftpd daemon started by its inetd daemon and have an account defined that limits the access of the tftpd daemon. Use the procedure defined by the tftpd command to setup the TFTP environment and the nobody account.

Note: The tftp and utftp commands should not be available when your host is operating in secure mode.

The tftp command ignores duplicate acknowledgments for any block sent and sends an error packet and exit if a block with an inappropriate (future) block number arrives. It also ignores duplicate data blocks if they have already been received and sends an error packet and exits.

RFC2349 Option Negotiation

As of AIX® 5.3, the tftp client is capable of negotiating the following TFTP options with the server: block size (blksize), transfer size (tsize), and timeout (timeout). Larger transfer block size can improve transfer performance, tsize reports the file size before the transfer to check for available space, and timeout negotiates the retransmit timeout. The TFTP server must support RFC2349 for option negotiation to take place.

Access Control

The /etc/tftpaccess.ctl file is searched for lines that start with allow: or deny:. Other lines are ignored. If the file doesn't exist, access is allowed. The allowed directories and files can be accessed and the denied directories cannot be accessed. For example, the /usr directory might be allowed and the /usr/ucb directory might be denied. This means that any directory or file in the /usr directory, except the /usr/ucb directory, can be accessed. The entries in the /etc/tftpaccess.ctl file must be absolute path names.

The /etc/tftpaccess.ctl file should be write-only by the root user and readable by all groups and others (that is, owned by root with permissions of 644). The user nobody must be able to read the /etc/tftpaccess.ctl file. Otherwise, the tftpd daemon is not able to recognize the existence of the file and allows access to the entire system. For more information, refer to the sample tftpaccess.ctl file, which resides in the /usr/samples/tcpip directory.

The search algorithm assumes that the local path name used in the tftp command is an absolute path name. It searches the /etc/tftpaccess.ctl file looking for allow:/. It repeatedly searches for allowed path names with each partial path name constructed by adding the next component from the file path name. The longest path name matched is the one allowed. It then does the same with denied names, starting with the longest allowed path name matched.

For example, if the file path name were /a/b/c and the /etc/tftpaccess.ctl file contained allow:/a/b and deny:/a, one allowed match would be made (/a/b) and no denied match starting with /a/b would be made, and access would be allowed.

If the /etc/tftpaccess.ctl file contained allow:/a and deny:/a/b, one allowed match would be made (/a) and one denied match starting with /a (/a/b) would be made, and access would be denied. If the /etc/tftpaccess.ctl file contained allow:/a/b and also contained deny:/a/b, access would be denied because allowed names are searched first.

Note: Further information and example configurations for Xstations, Diskless clients, and restricted entry can be found in the /usr/samples/tcpip/tftpaccess.ctl file.

The tftp and utftp commands have two forms: interactive form and command-line form.

Interactive Form

In the interactive form, the tftp and utftp commands are issued alone or with a Host parameter that specifies the default host to use for file transfers during this session. If you choose, you can also specify with the Port parameter which port the tftp or utftp connection should use, such as the one specified for mail in the /etc/services file. When you enter the interactive form of either of these commands, the tftp> prompt is displayed.

When transferring data to a remote host, the transferred data is placed in the directory specified by the RemoteName parameter. The remote name must be a fully specified file name, and the remote file must both exist and have write permission set for others. The tftp command attempts to write the data to the specified file. However, if the remote TFTP server does not have the appropriate privileges to write the remote file or if the file does not already exist, the transfer is unsuccessful. This can be overridden using the tftpd daemon.

Command-Line Form

The command-line forms of the tftp and utftp commands are equivalent, except that the utftp command does not overwrite a local file. The tftp command can overwrite a file, but prompts the user before doing so. Because it is not interactive, the command line form of the utftp command can be more useful than the tftp command in a pipe. In the command line form, all of the arguments to either command are specified on the command line, and no prompt is displayed.

Subcommands

The tftp and utftp subcommands can be entered in either their interactive form or in their command-line form.

Subcommands Used in the Interactive Form

Once the tftp> prompt is displayed, the following subcommands can be issued:

Item Description
? [Subcommand] Displays help information. If a Subcommand parameter is specified, only information about that subcommand is displayed.
ascii Synonym for the mode ascii subcommand.
binary Synonym for the mode binary subcommand. This subcommand is used in the interactive mode. The image subcommand accomplishes the same thing as the mode binary subcommand, but is used on the command line.
blksize Number of Bytes Enables the blksize option negotiation with the server. If successfully negotiated, this can substantially improve transfer rates. The transfer block size must be at least 8 octets and can be as high as 65464 octets. The default is 512 octets.
connect Host [Port] Sets the remote host, and optionally the port, for file transfers. Since the TFTP protocol does not maintain connections between transfers, the connect subcommand does not create a connection to the specified host, but stores it for transfer operations. Because the remote host can be specified as part of the get or put subcommand, which overrides any host previously specified, the connect subcommand is not required.

get RemoteFile [LocalFile]

Item Description
get RemoteFile RemoteFile RemoteFile [RemoteFile . . . ]  Gets a file or set of files from the remote host to the local host. Each of the RemoteFile parameters can be specified in one of the following two ways:
  • As a file (File) that exists on the remote host if a default host has already been specified.
  • As a host file (Host:File), where Host is the remote host and File is the name of the file to copy to the local system. If this form of the parameter is used, the last host specified becomes the default host for later transfers in this tftp session.
mode Type Sets the type (Type) of transfer mode to either ascii or binary. A transfer mode of ascii is the default.

put LocalFile [RemoteFile]

Item Description
put LocalFile LocalFile LocalFile [LocalFile . . . ] RemoteDirectory             Puts a file or set of files from the local host onto the remote host. The RemoteDirectory and RemoteFile parameters can be specified in one of the following two ways:
  • As a file or directory that exists on the remote host if a default host has already been specified.
  • With Host:RemoteFile parameter, where Host is the remote host and RemoteFile is the name of the file or directory on the remote system. If this form of the parameter is used, the last host specified becomes the default host for later transfers in this tftp session.

In either case, the remote file or directory name must be a fully specified path name, even if the local and remote directories have the same name. If a remote directory is specified, the remote host is assumed to be a UNIX machine. The default value of the put subcommand is write-replace, but you can add an option in the tftpd daemon to allow write-create.

quit Exits the tftp session. An End-Of-File key sequence also exits the program.
status Shows the current status of the tftp program, including, for example, the current transfer mode (ascii or binary), connection status, and time-out value.
timeout Value Sets the total transmission time out to the number of seconds specified by the Value parameter. The Value parameter must be 1 second or greater (the default is 5 seconds).
trace Turns packet tracing on or off.
tsize Enables the tsize option negotiation with the server. This allows the file size to be known before the transfer starts. If allocation is exceeded, an error is returned and the file transfer does not occur.
verbose Turns verbose mode, which displays additional information during file transfer, on or off.

Subcommands Used in the Command Line Form

In this form, if the Action flag is:

Item Description
-w or -p Writes (or puts) local data, specified by the LocalName parameter, to the file specified by the RemoteName parameter on the remote host specified by the Host parameter. If the LocalName parameter is a file name, the tftp command transfers the specified local file. If the LocalName parameter is specified as a - (dash), the tftp command transfers data from local standard input to the remote host. When the LocalName parameter is standard input, the tftp command allows 25 seconds for all input to be entered before it times out.
-r or -g or -o Reads (or gets) remote data from the file specified by the RemoteName parameter at the remote host specified by the Host parameter and writes it to the file specified by the LocalName parameter. If the LocalName parameter is a file name, the tftp command writes the data to the specified local file. For the -r and -g actions, the tftp command prompts for verification before overwriting an existing local file. For the -o action, the tftp command overwrites an existing local file without prompting. If the LocalName parameter is specified as a - (dash), the tftp command writes the data to local standard output.
Note: Since the tftp -g and tftp -r commands prompt before overwriting an existing local file, it may be impractical to use the tftp command in a pipe. The utftp command performs the same -r and -g actions as the tftp command, but simply stops before overwriting a local file. Thus, the utftp command may be more appropriate for use in a pipe.

For both of the following modes of file transfer, the RemoteName parameter is the name of a file that has write permission set for others. Note that the RemoteName parameter must be in double quotes (" ") if it contains shell special characters.

The mode of transfer is one of the following:

Item Description
netascii Transfers the data as 7-bit ASCII characters in 8-bit transfer bytes. This is the default.
image Transfers the data as 8-bit binary data bytes in 8-bit transfer bytes, with no conversion. image transfer can be more efficient than netascii transfer when transferring between two hosts. It is recommended that netascii be used when transferring ASCII files from a workstation to a different type of host.

Examples

The following examples distinguish the differences between the interactive form and the command line form of the tftp command:

Using the Interactive Form of the tftp Command

To enter the tftp command, check the current status, connect to a remote host, and transfer a file from a remote host to your local host, enter:

tftp

The tftp> prompt is displayed. Enter the status subcommand following this prompt:

status

A message similar to the following is displayed on your screen:

Not connected.
Mode: netascii   Verbose: off   Tracing: off
Max-timeout: 25 seconds
tftp> _

After the tftp> prompt, enter the connect subcommand and the name of the remote system to which you want to connect:

tftp>  connect host1

The tftp> prompt is displayed as an indication that you are connected to host1. Following the tftp> prompt, enter the get subcommand to transfer the file update from the remote host to your local host.

get /home/alice/update update 

The /home/alice directory on the remote host must have read permission set for others. The /home/alice/update file from host1 was transferred to the update file on your local system. In this example, the user is connected to host1 and the update file is transferred from host1 to the local host.

Using the Command Line Form of the tftp Command

  1. To copy a text file from a remote host and write it to a local file, enter:

    tftp  -g newsched host1 /home/john/schedule
    $ _

    In this example, the /home/john/schedule file was copied from the remote host host1 and written to the local file newsched.
  2. To copy a file from a remote host and redirect the output to standard output of the local host, enter:

    tftp  -g - host3 /etc/hosts

    If the copy is successful, information similar to the following is displayed on your screen:
    192.100.13.3 nameserver
    192.100.13.3 host2
    192.100.13.5 host1
    192.100.13.7 host3
    192.100.13.3 timeserver
    Received 128 bytes in 0.4 seconds
    $ _
    In this example, the /etc/hosts file from remote host host3 was copied and the output redirected to standard output of the local host.
  3. To copy a file from a remote host, pipe it to the grep command, and write it to a local file, enter:

    utftp  -g - host1 /home/john/schedule | grep Jones > jones.todo
    $ _

    In this example, the /home/john/schedule file was copied from the remote host host1. This file was then piped to the grep command and written into the local file jones.todo.
  4. To copy a file to another system, enter:

    tftp  -p /home/jeanne/test host2 /tmp/test

    If the copy is successful, information similar to the following is displayed on your screen:
    Sent 94146 bytes in 6.7 seconds
    In this example, the /home/jeanne/test file was sent to the /tmp directory on the remote host host2.
  5. To copy a binary file to another system, enter:

    tftp  -p core host3 /tmp/core image

    If the copy is successful, information similar to the following is displayed on your screen:
    Sent 309295 bytes in 15 seconds
    In this example, the binary file core from the current directory was sent to the /tmp directory on remote host host3.

Files

Item Description
/etc/tftpaccess.ctl Allows or denies access to files and directories.