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