1.\" $Id: fetch.1,v 1.18 1997/07/25 19:35:41 wollman Exp $ 2.Dd July 2, 1996 3.Dt FETCH 1 4.Os FreeBSD 2.2 5.Sh NAME 6.Nm fetch 7.Nd retrieve a file by Uniform Resource Locator 8.Sh SYNOPSIS 9.Nm fetch 10.Op Fl MPabmnpqr 11.Op Fl o Ar file 12.Ar URL 13.Op Ar ... 14.Nm fetch 15.Op Fl MPRmnpqr 16.Op Fl o Ar file 17.Op Fl c Ar dir 18.Fl f Ar file 19.Fl h Ar host 20.Sh DESCRIPTION 21.Nm fetch 22allows a user to transfer files from a remote network site using 23either the 24.Tn FTP 25or the 26.Tn HTTP 27protocol. In the first form of the command, the 28.Ar URL 29may be of the form 30.Li http://site.domain/path/to/the/file 31or 32.Li ftp://site.domain/path/to/the/file. 33To denote a local filename to be copied or linked to (see the 34.Fl l 35flag below), the 36.Em file:/path/to/the/file 37URL form is used. 38.Pp 39The second form of the command can be used to get a file using the 40.Tn FTP 41protocol, specifying the file name and the remote host with the 42.Fl h 43and the 44.Fl f 45flags. 46.Pp 47The following options are available: 48.Bl -tag -width Fl 49.It Fl a 50Automatically retry the transfer upon soft failures. 51.It Fl b 52Work around a bug in some 53.Tn HTTP 54servers which fail to correctly implement the 55.Tn TCP 56protocol. 57.It Fl c Ar dir 58The file to retrieve is in directory 59.Ar dir 60on the remote host. 61.It Fl f Ar file 62The file to retrieve is named 63.Ar file 64on the remote host. 65.It Fl h Ar host 66The file to retrieve is located on the host 67.Ar host . 68.It Fl l 69If target is a 70.Ar file:/ 71style of URL, make a link to the target rather than trying 72to copy it. 73.It Fl M 74.It Fl m 75Mirror mode: Set the modification time of the file so that it is 76identical to the modification time of the file at the remote host. 77If the file already exists on the local host and is identical (as 78gauged by size and modification time), no transfer is done. 79.It Fl n 80Don't preserve the modtime of the transfered file, use the current time. 81.It Fl o Ar file 82Set the output file name to 83.Ar file . 84By default, a ``pathname'' is extracted from the specified URI, and 85its basename is used as the name of the output file. A 86.Ar file 87argument of 88.Sq Li \&- 89indicates that results are to be directed to the standard output. 90.It Fl P 91.It Fl p 92Use the passive mode of the 93.Tn FTP 94protocol. This is useful for crossing certain sorts of firewalls. 95.It Fl q 96Quiet mode. Do not report transfer progress on the terminal. 97.It Fl R 98The filenames specified are ``precious'', and should not be deleted 99under any circumstances, even if the transfer failed or was incomplete. 100.It Fl r 101Restart a previously interrupted transfer. 102.It Fl t 103Ensure that the use of T/TCP is not attempted for connections. This is 104used to workaround bugs in some remote OS stacks that give improper 105replies to T/TCP connections. 106.It Fl T Ar seconds 107Set timeout value to 108.Ar seconds. 109Overrides the environment variables 110.Ev FTP_TIMEOUT 111for ftp transfers or 112.Ev HTTP_TIMEOUT 113for http transfers if set. 114.It Fl v 115Increase verbosity. More 116.Fl v Ns \&'s 117result in more information. 118.El 119.Pp 120Many options are also controlled solely by the environment (this is a 121bug). 122.Sh PROXY SERVERS 123Many sites use application gateways (``proxy servers'') in their 124firewalls in order to allow communication across the firewall using a 125trusted protocol. The 126.Nm fetch 127program can use both the 128.Tn FTP 129and the 130.Tn HTTP 131protocol with a proxy server. 132.Tn FTP 133proxy servers can only relay 134.Tn FTP 135requests; 136.Tn HTTP 137proxy servers can relay both 138.Tn FTP 139and 140.Tn HTTP 141requests. 142A proxy server can be configured by defining an environment variable 143named 144.Dq Va PROTO Ns Ev _PROXY , 145where 146.Va PROTO 147is the name of the protocol in upper case. The value of the 148environment variable specifies a hostname, optionally followed by a 149colon and a port number. 150.Pp 151The 152.Tn FTP 153proxy client passes the remote username, host and port as the 154.Tn FTP 155session's username, in the form 156.Do Va remoteuser Ns Li \&@ Ns Va remotehost 157.Op Li \^@ Ns Va port 158.Dc . 159The 160.Tn HTTP 161proxy client simply passes the originally-requested URI to the remote 162server in an 163.Tn HTTP 164.Dq Li GET 165request. HTTP proxy authentication is not yet implemented. 166.Sh HTTP AUTHENTICATION 167The 168.Tn HTTP 169protocol includes support for various methods of authentication. 170Currently, the 171.Dq basic 172method, which provides no security from packet-sniffing or 173man-in-the-middle attacks, is the only method supported in 174.Nm fetch . 175Authentication is enabled by the 176.Ev HTTP_AUTH 177and 178.Ev HTTP_PROXY_AUTH 179environment variables. Both variables have the same format, which 180consists of space-separated list of parameter settings, where each 181setting consists of a colon-separated list of parameters. The first 182two parameters are always the (case-insensitive) authentication scheme 183name and the realm in which authentication is to be performed. If the 184realm is specified as 185.Sq Li \&* , 186then it will match all realms not specified otherwise. 187.Pp 188For the 189.Li basic 190authentication scheme uses two additional optional parameters; the 191first is a user name, and the second is the password associated with 192it. If either the password or both parameters are not specified in 193the environment, and the standard input of 194.Nm 195is connected to a terminal, then 196.Nm 197will prompt the user to enter the missing parameters. Thus, if the 198user is known as 199.Dq Li jane 200in the 201.Dq Li WallyWorld 202realm, and has a password of 203.Dq Li QghiLx79 204there, then she might set her 205.Ev HTTP_AUTH 206variable to: 207.Bl -enum -offset indent 208.It 209.Dq Li basic:WallyWorld:jane:QghiLx79 210.It 211.Dq Li basic:WallyWorld:jane , 212or 213.It 214.Dq Li basic:WallyWorld 215.El 216.Pp 217and 218.Nm 219will prompt for the missing information if it is required. She might 220also specify a realm of 221.Dq Li \&* 222instead of 223.Dq Li WallyWorld 224to indicate that the parameters can be applied to any realm. (This is 225most commonly used in a construction such as 226.Dq Li basic:* , 227which indicates to 228.Nm 229that it may offer to do 230.Li basic 231authentication for any realm. 232.Sh ERRORS 233The 234.Nm 235command returns zero on success, or a non-zero value from 236.Aq Pa sysexits.h 237on failure. If multiple URIs are given for retrieval, 238.Nm 239will attempt all of them and return zero only if all succeeded 240(otherwise it will return the error from the last failure). 241.Sh ENVIRONMENT 242.Bl -tag -width FTP_PASSIVE_MODE -offset indent 243.It Ev FTP_TIMEOUT 244maximum time, in seconds, to wait before aborting an 245.Tn FTP 246connection. 247.It Ev FTP_LOGIN 248the login name used for 249.Tn FTP 250transfers (default 251.Dq Li anonymous ) 252.It Ev FTP_PASSIVE_MODE 253force the use of passive mode FTP 254.It Ev FTP_PASSWORD 255the password used for 256.Tn FTP 257transfers (default 258.Dq Va yourname Ns Li \&@ Ns Va yourhost ) 259.It Ev FTP_PROXY 260the address (in the form 261.Do Va hostname Ns 262.Op Li : Ns Va port 263.Dc ) 264of a proxy server which understands 265.Tn FTP 266.It Ev HTTP_AUTH 267defines authentication parameters for 268.Tn HTTP 269.It Ev HTTP_PROXY 270the address (in the form 271.Do Va hostname Ns 272.Op Li : Ns Va port 273.Dc ) 274of a proxy server which understands 275.Tn HTTP 276.It Ev HTTP_PROXY_AUTH 277defines authentication parameters for 278.Tn HTTP 279proxy servers 280.It Ev HTTP_TIMEOUT 281maximum time, in seconds, to wait before aborting an 282.Tn HTTP 283connection. 284.Sh SEE ALSO 285.Xr ftp 1 , 286.Xr tftp 1 287.Sh HISTORY 288The 289.Nm fetch 290command appeared in 291.Fx 2.1.5 . 292.Sh AUTHORS 293The original implementation of 294.Nm 295was done by Jean-Marc Zucconi. It was extensively re-worked for 296.Fx 2.2 297by Garrett Wollman. 298.Sh BUGS 299There are too many environment variables and command-line options. 300.Pp 301The 302.Fl a 303option is only implemented for certain kinds of 304.Tn HTTP 305failures, and no 306.Tn FTP 307failures. 308.Pp 309Only the 310.Dq basic 311authentication mode is implemented for 312.Tn HTTP . 313This should be replaced by digest authentication. 314.Pp 315The 316.Fl b 317flag should not be necessary. 318