FETCH(1)

NAME
fetch - retrieve a file by Uniform Resource Locator

SYNOPSIS
fetch [-MPamnpqr] [-o file] URL [...]
fetch [-MPRmnpqr] [-o file] [-c dir] -f file -h host

DESCRIPTION
fetch allows a user to transfer files from a remote network site using either the FTP or the HTTP protocol. In the first form of the command, the URL may be of the form http://site.domain/path/to/the/file or ftp://site.domain/path/to/the/file. To denote a local filename to be copied or linked to (see the -l flag below), the file:/path/to/the/file URL form is used.

The second form of the command can be used to get a file using the FTP protocol, specifying the file name and the remote host with the -h and the -f flags.

The following options are available:

-a  Automatically retry the transfer upon soft failures.

-c dir
    The file to retrieve is in directory dir on the remote host.

-f file
    The file to retrieve is named file on the remote host.

-h host
    The file to retrieve is located on the host host.

-l  If target is a file:/ style of URL, make a link to the target rather than trying to copy it.

-M

-m  Mirror mode: Set the modification time of the file so that it is identical to the modification time of the file at the remote host. If the file already exists on the local host and is identical (as gauged by size and modification time), no transfer is done.

-n  Don't preserve the modtime of the transfered file, use the current time.

-o file
    Set the output file name to file. By default, a ``pathname'' is extracted from the specified URI, and its basename is used as the name of the output file. A file argument of ‘-’ indicates that results are to be directed to the standard output.

-P

-p  Use the passive mode of the FTP protocol. This is useful for crossing certain sorts of firewalls.

-q  Quiet mode. Do not report transfer progress on the terminal.

-R  The filenames specified are ``precious'', and should not be deleted under any circumstances, even if the transfer failed or was incomplete.

-r  Restart a previously interrupted transfer.

-T seconds
    Set timeout value to seconds. Overrides the environment variables FTP_TIMEOUT for ftp transfers or HTTP_TIMEOUT for http transfers if set.

-v  Increase verbosity. More -v's result in more information.

Many options are also controlled solely by the environment (this is a bug).

PROXY SERVERS
Many sites use application gateways (``proxy servers'') in their firewalls in order to allow communication across the firewall using a trusted protocol. The fetch program can use both the FTP and the HTTP protocol with a proxy server. FTP proxy servers can only relay FTP requests; HTTP proxy servers can relay both FTP and HTTP requests. A proxy server can be configured by defining an environment variable named “PROTO_PROXY”, where PROTO is the name of the protocol in upper case. The value of the environment variable specifies a hostname, optionally followed by a colon and a port number.

The FTP proxy client passes the remote username, host and port as the FTP session's username, in the form “remoteuser@remotehost [@port] ”. The HTTP proxy client simply passes the originally-requested URI to the remote server in an HTTP “GET” request. HTTP proxy authentication is not yet implemented.

HTTP AUTHENTICATION
The HTTP protocol includes support for various methods of authentication. Currently, the “basic” method, which provides no security from packet-sniffing or man-in-the-middle attacks, is the only method supported in fetch. Authentication is enabled by the HTTP_AUTH and HTTP_PROXY_AUTH environment variables. Both variables have the same format, which consists of space-separated list of parameter settings, where each setting consists of a colon-separated list of parameters. The first two parameters are always the (case-insensitive) authentication scheme name and the realm in which authentication is to be performed. If the realm is specified as ‘*’, then it will match all realms not specified otherwise.

For the basic authentication scheme uses two additional optional parameters; the first is a user name, and the second is the password associated with it. If either the password or both parameters are not specified in the environment, and the standard input of fetch is connected to a terminal, then fetch will prompt the user to enter the missing parameters. Thus, if the user is known as “jane” in the “WallyWorld” realm, and has a password of “QghiLx79” there, then she might set her HTTP_AUTH variable to:

1.  “basic:WallyWorld:jane:QghiLx79”

2.  “basic:WallyWorld:jane”, or

3.  “basic:WallyWorld”

and fetch will prompt for the missing information if it is required. She might also specify a realm of “*” instead of “WallyWorld” to indicate that the parameters can be applied to any realm. (This is most commonly used in a construction such as “basic:*”, which indicates to fetch that it may offer to do basic authentication for any realm.

ERRORS
The fetch command returns zero on success, or a non-zero value from <sysexits.h> on failure. If multiple URIs are given for retrieval, fetch will attempt all of them and return zero only if all succeeded (otherwise it will return the error from the last failure).

ENVIRONMENT

FTP_TIMEOUT
    maximum time, in seconds, to wait before aborting an FTP connection.

FTP_LOGIN
    the login name used for FTP transfers (default “anonymous”)

FTP_PASSIVE_MODE
    force the use of passive mode FTP

FTP_PASSWORD
    the password used for FTP transfers (default “yourname@yourhost”)

FTP_PROXY
    the address (in the form “hostname [:port] ”) of a proxy server which understands FTP

HTTP_AUTH
    defines authentication parameters for HTTP

HTTP_PROXY
    the address (in the form “hostname [:port] ”) of a proxy server which understands HTTP

HTTP_PROXY_AUTH
    defines authentication parameters for HTTP proxy servers

HTTP_TIMEOUT
    maximum time, in seconds, to wait before aborting an HTTP connection.

SEE ALSO
ftp(1), tftp(1)

HISTORY
The fetch command appeared in FreeBSD 2.1.5.

AUTHORS
The original implementation of fetch was done by Jean-Marc Zucconi. It was extensively re-worked for FreeBSD 2.2 by Garrett Wollman.

BUGS
There are too many environment variables and command-line options.

The -a option is only implemented for certain kinds of HTTP failures, and no FTP failures.

Only the “basic” authentication mode is implemented for HTTP. This should be replaced by digest authentication.