1.\" $FreeBSD$ 2.Dd February 22, 1999 3.Dt FETCH 1 4.Os FreeBSD 4.0 5.Sh NAME 6.Nm fetch 7.Nd retrieve a file by Uniform Resource Locator 8.Sh SYNOPSIS 9.Nm fetch 10.Op Fl AFMPablmnpqrtv 11.Op Fl S Ar size 12.Op Fl T Ar timeout 13.Op Fl o Ar file 14.Ar URL 15.Op Ar ... 16.Nm fetch 17.Op Fl FMPRlmnpqrv 18.Op Fl S Ar size 19.Op Fl o Ar file 20.Op Fl c Ar dir 21.Fl f Ar file 22.Fl h Ar host 23.Sh DESCRIPTION 24.Nm fetch 25allows a user to transfer files from a remote network site using 26either the 27.Tn FTP 28or the 29.Tn HTTP 30protocol. 31In the first form of the command, the 32.Ar URL 33may be of the form 34.Li http://site.domain/path/to/the/file 35or 36.Li ftp://site.domain/path/to/the/file . 37To denote a local filename to be copied or linked to (see the 38.Fl l 39flag below), the 40.Em file:/path/to/the/file 41URL form is used. See URL SYNTAX, below. 42.Pp 43The second form of the command can be used to get a file using the 44.Tn FTP 45protocol, specifying the file name and the remote host with the 46.Fl h 47and the 48.Fl f 49flags. 50.Pp 51The following options are available: 52.Bl -tag -width Fl 53.It Fl A 54Do not automatically follow ``temporary'' (302) redirects. Some 55broken Web sites will return a redirect instead of a not-found error 56when the requested object does not exist. 57.It Fl a 58Automatically retry the transfer upon soft failures. 59.It Fl b 60Work around a bug in some 61.Tn HTTP 62servers which fail to correctly implement the 63.Tn TCP 64protocol. 65.It Fl c Ar dir 66The file to retrieve is in directory 67.Ar dir 68on the remote host. 69.It Fl F 70Force restart without checking for the local file's date matching 71that of the remote file. Use this with 72.Fl r 73to restart a transfer of a partial file where the modification 74time on the local file has been changed and you are sure that the 75remote file is still the same, as this will prevent retrieval from 76starting anew. 77.It Fl f Ar file 78The file to retrieve is named 79.Ar file 80on the remote host. 81.It Fl h Ar host 82The file to retrieve is located on the host 83.Ar host . 84.It Fl l 85If target is a 86.Ar file:/ 87style of URL, make a link to the target rather than trying 88to copy it. 89.It Fl M 90.It Fl m 91Mirror mode: Set the modification time of the file so that it is 92identical to the modification time of the file at the remote host. 93If the file already exists on the local host and is identical (as 94gauged by size and modification time), no transfer is done. 95.It Fl n 96Don't preserve the modtime of the transferred file, use the current time. 97.It Fl o Ar file 98Set the output file name to 99.Ar file . 100By default, a ``pathname'' is extracted from the specified URI, and 101its basename is used as the name of the output file. A 102.Ar file 103argument of 104.Sq Li \&- 105indicates that results are to be directed to the standard output. 106.It Fl P 107.It Fl p 108Use the passive mode of the 109.Tn FTP 110protocol. This is useful for crossing certain sorts of firewalls. 111.It Fl q 112Quiet mode. 113Do not report transfer progress on the terminal. 114.It Fl R 115The filenames specified are ``precious'', and should not be deleted 116under any circumstances, even if the transfer failed or was incomplete. 117.It Fl r 118Restart a previously interrupted transfer. 119.It Fl S Ar bytes 120Require the file size reported by 121.Tn FTP 122or 123.Tn HTTP 124server to match the value specified with this option. 125On mismatch, a message is printed and the file will not be fetched. 126If the server does not support reporting of file sizes, the option 127will be ignored and the file will be retrieved anyway. 128This option is useful to prevent 129.Nm fetch 130from downloading a file that is either incomplete or the wrong version, 131given the correct size of the file in advance. 132.It Fl s 133Ask server for size of file in bytes and print it to stdout. 134Do not 135actually fetch the file. 136.It Fl T Ar seconds 137Set timeout value to 138.Ar seconds. 139Overrides the environment variables 140.Ev FTP_TIMEOUT 141for ftp transfers or 142.Ev HTTP_TIMEOUT 143for http transfers if set. 144.It Fl t 145Work around a different set of buggy 146.Tn TCP 147implementations. 148.It Fl v 149Increase verbosity. More 150.Fl v Ns \&'s 151result in more information. 152.El 153.Pp 154Many options are also controlled solely by the environment (this is a 155bug). 156.Sh URL SYNTAX 157.Nm 158accepts 159.Tn http 160and 161.Tn ftp 162URL's, as described in RFC1738. For 163.Tn ftp 164URL's, a username and password may be specified, using the syntax 165.Li ftp://user:password@host/. 166If the path is to be absolute, as opposed to relative to the user's 167home directory, it must start with %2F, as in 168.Li ftp://root:mypass@localhost/%2Fetc/passwd . 169.Nm Fetch 170condenses multiple slashes in an 171.Tn ftp 172URL into a single slash; literal multiple slashes translate to an 173.Tn ftp 174protocol error. 175.Sh PROXY SERVERS 176Many sites use application gateways (``proxy servers'') in their 177firewalls in order to allow communication across the firewall using a 178trusted protocol. The 179.Nm fetch 180program can use both the 181.Tn FTP 182and the 183.Tn HTTP 184protocol with a proxy server. 185.Tn FTP 186proxy servers can only relay 187.Tn FTP 188requests; 189.Tn HTTP 190proxy servers can relay both 191.Tn FTP 192and 193.Tn HTTP 194requests. 195A proxy server can be configured by defining an environment variable 196named 197.Dq Va PROTO Ns Ev _PROXY , 198where 199.Va PROTO 200is the name of the protocol in upper case. The value of the 201environment variable specifies a hostname, optionally followed by a 202colon and a port number. 203.Pp 204The 205.Tn FTP 206proxy client passes the remote username, host and port as the 207.Tn FTP 208session's username, in the form 209.Do Va remoteuser Ns Li \&@ Ns Va remotehost 210.Op Li \&@ Ns Va port 211.Dc . 212The 213.Tn HTTP 214proxy client simply passes the originally-requested URI to the remote 215server in an 216.Tn HTTP 217.Dq Li GET 218request. HTTP proxy authentication is not yet implemented. 219.Sh HTTP AUTHENTICATION 220The 221.Tn HTTP 222protocol includes support for various methods of authentication. 223Currently, the 224.Dq basic 225method, which provides no security from packet-sniffing or 226man-in-the-middle attacks, is the only method supported in 227.Nm fetch . 228Authentication is enabled by the 229.Ev HTTP_AUTH 230and 231.Ev HTTP_PROXY_AUTH 232environment variables. Both variables have the same format, which 233consists of space-separated list of parameter settings, where each 234setting consists of a colon-separated list of parameters. The first 235two parameters are always the (case-insensitive) authentication scheme 236name and the realm in which authentication is to be performed. If the 237realm is specified as 238.Sq Li \&* , 239then it will match all realms not specified otherwise. 240.Pp 241The 242.Li basic 243authentication scheme uses two additional optional parameters; the 244first is a user name, and the second is the password associated with 245it. If either the password or both parameters are not specified in 246the environment, and the standard input of 247.Nm 248is connected to a terminal, then 249.Nm 250will prompt the user to enter the missing parameters. Thus, if the 251user is known as 252.Dq Li jane 253in the 254.Dq Li WallyWorld 255realm, and has a password of 256.Dq Li QghiLx79 257there, then she might set her 258.Ev HTTP_AUTH 259variable to: 260.Bl -enum -offset indent 261.It 262.Dq Li basic:WallyWorld:jane:QghiLx79 263.It 264.Dq Li basic:WallyWorld:jane , 265or 266.It 267.Dq Li basic:WallyWorld 268.El 269.Pp 270and 271.Nm 272will prompt for any missing information when it is required. She might 273also specify a realm of 274.Dq Li \&* 275instead of 276.Dq Li WallyWorld 277to indicate that the parameters can be applied to any realm. (This is 278most commonly used in a construction such as 279.Dq Li basic:* , 280which indicates to 281.Nm 282that it may offer to do 283.Li basic 284authentication for any realm. 285.Sh ERRORS 286The 287.Nm 288command returns zero on success, or a non-zero value from 289.Aq Pa sysexits.h 290on failure. If multiple URIs are given for retrieval, 291.Nm 292will attempt all of them and return zero only if all succeeded 293(otherwise it will return the error from the last failure). 294.Sh ENVIRONMENT 295.Bl -tag -width FTP_PASSIVE_MODE -offset indent 296.It Ev FTP_TIMEOUT 297maximum time, in seconds, to wait before aborting an 298.Tn FTP 299connection. 300.It Ev FTP_LOGIN 301the login name used for 302.Tn FTP 303transfers (default 304.Dq Li anonymous ) 305.It Ev FTP_PASSIVE_MODE 306force the use of passive mode FTP 307.It Ev FTP_PASSWORD 308the password used for 309.Tn FTP 310transfers (default 311.Dq Va yourname Ns Li \&@ Ns Va yourhost ) 312.It Ev FTP_PROXY 313the address (in the form 314.Do Va hostname Ns 315.Op Li : Ns Va port 316.Dc ) 317of a proxy server which understands 318.Tn FTP 319.It Ev HTTP_AUTH 320defines authentication parameters for 321.Tn HTTP 322.It Ev HTTP_PROXY 323the address (in the form 324.Do Va hostname Ns 325.Op Li : Ns Va port 326.Dc ) 327of a proxy server which understands 328.Tn HTTP 329.It Ev HTTP_PROXY_AUTH 330defines authentication parameters for 331.Tn HTTP 332proxy servers 333.It Ev HTTP_TIMEOUT 334maximum time, in seconds, to wait before aborting an 335.Tn HTTP 336connection. 337.Sh SEE ALSO 338.Xr ftp 1 , 339.Xr tftp 1 340.Rs 341.%A R. Fielding 342.%A J. Gettys 343.%A J. Mogul 344.%A H. Frystyk 345.%A T. Berners-Lee 346.%T "Hypertext Transfer Protocol \-\- HTTP/1.1" 347.%O RFC 2068 348.%D January 1997 349.Re 350.Rs 351.%A T. Berners-Lee 352.%A L. Masinter 353.%A M. McCahill 354.%T "Uniform Resource Locators (URL)" 355.%O RFC 1738 356.%D December 1994 357.Re 358.Rs 359.%A J. Postel 360.%A J.K. Reynolds 361.%T "File Transfer Protocol" 362.%O RFC 959 / STD 9 363.%D October 1985 364.Re 365.Rs 366.%A M.R. Horton 367.%T "Standard for interchange of USENET messages." 368.%O RFC 850 369.%D June 1983 370.Re 371.Sh HISTORY 372The 373.Nm fetch 374command appeared in 375.Fx 2.1.5 . 376.Sh AUTHORS 377The original implementation of 378.Nm 379was done by 380.An Jean-Marc Zucconi . 381It was extensively re-worked for 382.Fx 2.2 383by 384.An Garrett Wollman . 385.Sh BUGS 386There are too many environment variables and command-line options. 387.Pp 388The 389.Fl a 390option is only implemented for certain kinds of 391.Tn HTTP 392failures, and no 393.Tn FTP 394failures. 395.Pp 396Only the 397.Dq basic 398authentication mode is implemented for 399.Tn HTTP . 400This should be replaced by digest authentication. 401.Pp 402Some 403.Tn TCP 404implementations (other than 405.Tn FreeBSD ) 406fail to correctly implement cases where the 407.Dv SYN 408and/or 409.Dv FIN 410control flags are specified in packets which also contain data. 411The 412.Sq Fl t 413flag works around the latter deficiency and the 414.Sq Fl b 415flag works around the former. Since these are errors of the server's 416.Tn TCP 417stack, the best we can do is provide these workarounds. Given a correct 418server, an optimal 419.Tn HTTP 420transfer without 421.Fl t 422and 423.Fl b 424involves a minimum of two round trips (for small replies), one less than 425other implementations. 426.Pp 427The 428.Tn HTTP 429standard requires interpretation of the 430.Tn RFC 850 431date format, which does not provide a century indication. Versions of 432.Nm fetch 433prior to 434.Fx 3.1 435would interpret all such dates as being in the 1900s. This version of 436.Nm fetch 437interprets such dates according to the rule given in 438.Tn RFC 2068 : 439.Bd -literal -offset indent 440 o HTTP/1.1 clients and caches should assume that an RFC-850 date 441 which appears to be more than 50 years in the future is in fact 442 in the past (this helps solve the "year 2000" problem). 443.Ed 444