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