1.\"- 2.\" Copyright (c) 2000-2011 Dag-Erling Smørgrav 3.\" All rights reserved. 4.\" Portions Copyright (c) 1999 Massachusetts Institute of Technology; used 5.\" by permission. 6.\" 7.\" Redistribution and use in source and binary forms, with or without 8.\" modification, are permitted provided that the following conditions 9.\" are met: 10.\" 1. Redistributions of source code must retain the above copyright 11.\" notice, this list of conditions and the following disclaimer 12.\" in this position and unchanged. 13.\" 2. Redistributions in binary form must reproduce the above copyright 14.\" notice, this list of conditions and the following disclaimer in the 15.\" documentation and/or other materials provided with the distribution. 16.\" 3. The name of the author may not be used to endorse or promote products 17.\" derived from this software without specific prior written permission. 18.\" 19.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 20.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 21.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 22.\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 23.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 24.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 28.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29.\" 30.\" $FreeBSD$ 31.\" 32.Dd September 27, 2011 33.Dt FETCH 1 34.Os 35.Sh NAME 36.Nm fetch 37.Nd retrieve a file by Uniform Resource Locator 38.Sh SYNOPSIS 39.Nm 40.Op Fl 146AadFlMmnPpqRrsUv 41.Op Fl -allow-sslv2 42.Op Fl B Ar bytes 43.Op Fl -bind-address= Ns Ar host 44.Op Fl -ca-cert= Ns Ar file 45.Op Fl -ca-path= Ns Ar dir 46.Op Fl -cert= Ns Ar file 47.Op Fl -crl= Ns Ar file 48.Op Fl i Ar file 49.Op Fl -key= Ns Ar file 50.Op Fl N Ar file 51.Op Fl -no-passive 52.Op Fl -no-proxy= Ns Ar list 53.Op Fl -no-sslv3 54.Op Fl -no-tlsv1 55.Op Fl -no-verify-hostname 56.Op Fl -no-verify-peer 57.Op Fl o Ar file 58.Op Fl -referer= Ns Ar URL 59.Op Fl S Ar bytes 60.Op Fl T Ar seconds 61.Op Fl -user-agent= Ns Ar agent-string 62.Op Fl w Ar seconds 63.Ar URL ... 64.Nm 65.Op Fl 146AadFlMmnPpqRrsUv 66.Op Fl B Ar bytes 67.Op Fl -bind-address= Ns Ar host 68.Op Fl -ca-cert= Ns Ar file 69.Op Fl -ca-path= Ns Ar dir 70.Op Fl -cert= Ns Ar file 71.Op Fl -crl= Ns Ar file 72.Op Fl i Ar file 73.Op Fl -key= Ns Ar file 74.Op Fl N Ar file 75.Op Fl -no-passive 76.Op Fl -no-proxy= Ns Ar list 77.Op Fl -no-sslv3 78.Op Fl -no-tlsv1 79.Op Fl -no-verify-hostname 80.Op Fl -no-verify-peer 81.Op Fl o Ar file 82.Op Fl -referer= Ns Ar URL 83.Op Fl S Ar bytes 84.Op Fl T Ar seconds 85.Op Fl -user-agent= Ns Ar agent-string 86.Op Fl w Ar seconds 87.Fl h Ar host Fl f Ar file Oo Fl c Ar dir Oc 88.Sh DESCRIPTION 89The 90.Nm 91utility provides a command-line interface to the 92.Xr fetch 3 93library. 94Its purpose is to retrieve the file(s) pointed to by the URL(s) on the 95command line. 96.Pp 97The following options are available: 98.Bl -tag -width Fl 99.It Fl 1 , -one-file 100Stop and return exit code 0 at the first successfully retrieved file. 101.It Fl 4 , -ipv4-only 102Forces 103.Nm 104to use IPv4 addresses only. 105.It Fl 6 , -ipv6-only 106Forces 107.Nm 108to use IPv6 addresses only. 109.It Fl A , -no-redirect 110Do not automatically follow ``temporary'' (302) redirects. 111Some broken Web sites will return a redirect instead of a not-found 112error when the requested object does not exist. 113.It Fl a , -retry 114Automatically retry the transfer upon soft failures. 115.It Fl -allow-sslv2 116[SSL] 117Allow SSL version 2 when negotiating the connection. 118.It Fl B Ar bytes , Fl -buffer-size= Ns Ar bytes 119Specify the read buffer size in bytes. 120The default is 4096 bytes. 121Attempts to set a buffer size lower than this will be silently 122ignored. 123The number of reads actually performed is reported at verbosity level 124two or higher (see the 125.Fl v 126flag). 127.It Fl -bind-address= Ns Ar host 128Specifies a hostname or IP address to which sockets used for outgoing 129connections will be bound. 130.It Fl c Ar dir 131The file to retrieve is in directory 132.Ar dir 133on the remote host. 134This option is deprecated and is provided for backward compatibility 135only. 136.It Fl -ca-cert= Ns Ar file 137[SSL] 138Path to certificate bundle containing trusted CA certificates. 139If not specified, 140.Pa /etc/ssl/cert.pem 141is used. 142The file may contain multiple CA certificates. The port 143.Pa security/ca_root_nss 144is a common source of a current CA bundle. 145.It Fl -ca-path= Ns Ar dir 146[SSL] 147The directory 148.Ar dir 149contains trusted CA hashes. 150.It Fl -cert= Ns Ar file 151[SSL] 152.Ar file 153is a PEM encoded client certificate/key which will be used in 154client certificate authentication. 155.It Fl -crl= Ns Ar file 156[SSL] 157Points to certificate revocation list 158.Ar file , 159which has to be in PEM format and may contain peer certificates that have 160been revoked. 161.It Fl d , -direct 162Use a direct connection even if a proxy is configured. 163.It Fl F , -force-restart 164In combination with the 165.Fl r 166flag, forces a restart even if the local and remote files have 167different modification times. 168Implies 169.Fl R . 170.It Fl f Ar file 171The file to retrieve is named 172.Ar file 173on the remote host. 174This option is deprecated and is provided for backward compatibility 175only. 176.It Fl h Ar host 177The file to retrieve is located on the host 178.Ar host . 179This option is deprecated and is provided for backward compatibility 180only. 181.It Fl i Ar file , Fl -if-modified-since= Ns Ar file 182If-Modified-Since mode: the remote file will only be retrieved if it 183is newer than 184.Ar file 185on the local host. 186(HTTP only) 187.It Fl -key= Ns Ar file 188[SSL] 189.Ar file 190is a PEM encoded client key that will be used in client certificate 191authentication in case key and client certificate are stored separately. 192.It Fl l , -symlink 193If the target is a file-scheme URL, make a symbolic link to the target 194rather than trying to copy it. 195.It Fl M 196.It Fl m , -mirror 197Mirror mode: if the file already exists locally and has the same size 198and modification time as the remote file, it will not be fetched. 199Note that the 200.Fl m 201and 202.Fl r 203flags are mutually exclusive. 204.It Fl N Ar file , Fl -netrc= Ns Ar file 205Use 206.Ar file 207instead of 208.Pa ~/.netrc 209to look up login names and passwords for FTP sites. 210See 211.Xr ftp 1 212for a description of the file format. 213This feature is experimental. 214.It Fl n , -no-mtime 215Do not preserve the modification time of the transferred file. 216.It Fl -no-passive 217Forces the FTP code to use active mode. 218.It Fl -no-proxy= Ns Ar list 219Either a single asterisk, which disables the use of proxies 220altogether, or a comma- or whitespace-separated list of hosts for 221which proxies should not be used. 222.It Fl -no-sslv3 223[SSL] 224Don't allow SSL version 3 when negotiating the connection. 225.It Fl -no-tlsv1 226[SSL] 227Don't allow TLS version 1 when negotiating the connection. 228.It Fl -no-verify-hostname 229[SSL] 230Do not verify that the hostname matches the subject of the 231certificate presented by the server. 232.It Fl -no-verify-peer 233[SSL] 234Do not verify the peer certificate against trusted CAs. 235.It Fl o Ar file , Fl output= Ns Ar file 236Set the output file name to 237.Ar file . 238By default, a ``pathname'' is extracted from the specified URI, and 239its basename is used as the name of the output file. 240A 241.Ar file 242argument of 243.Sq Li \&- 244indicates that results are to be directed to the standard output. 245If the 246.Ar file 247argument is a directory, fetched file(s) will be placed within the 248directory, with name(s) selected as in the default behaviour. 249.It Fl P 250.It Fl p , -passive 251Use passive FTP. 252These flags have no effect, since passive FTP is the default, but are 253provided for compatibility with earlier versions where active FTP was 254the default. 255To force active mode, use the 256.Fl -no-passive 257flag or set the 258.Ev FTP_PASSIVE_MODE 259environment variable to 260.Ql NO . 261.It Fl -referer= Ns Ar URL 262Specifies the referrer URL to use for HTTP requests. 263If 264.Ar URL 265is set to 266.Dq auto , 267the document URL will be used as referrer URL. 268.It Fl q , -quiet 269Quiet mode. 270.It Fl R , -keep-output 271The output files are precious, and should not be deleted under any 272circumstances, even if the transfer failed or was incomplete. 273.It Fl r , -restart 274Restart a previously interrupted transfer. 275Note that the 276.Fl m 277and 278.Fl r 279flags are mutually exclusive. 280.It Fl S Ar bytes , Fl -require-size= Ns Ar bytes 281Require the file size reported by the server to match the specified 282value. 283If it does not, a message is printed and the file is not fetched. 284If the server does not support reporting file sizes, this option is 285ignored and the file is fetched unconditionally. 286.It Fl s , -print-size 287Print the size in bytes of each requested file, without fetching it. 288.It Fl T Ar seconds , Fl -timeout= Ns Ar seconds 289Set timeout value to 290.Ar seconds . 291Overrides the environment variables 292.Ev FTP_TIMEOUT 293for FTP transfers or 294.Ev HTTP_TIMEOUT 295for HTTP transfers if set. 296.It Fl U , -passive-portrange-default 297When using passive FTP, allocate the port for the data connection from 298the low (default) port range. 299See 300.Xr ip 4 301for details on how to specify which port range this corresponds to. 302.It Fl -user-agent= Ns Ar agent-string 303Specifies the User-Agent string to use for HTTP requests. 304This can be useful when working with HTTP origin or proxy servers that 305differentiate between user agents. 306.It Fl v , -verbose 307Increase verbosity level. 308.It Fl w Ar seconds , Fl -retry-delay= Ns Ar seconds 309When the 310.Fl a 311flag is specified, wait this many seconds between successive retries. 312.El 313.Pp 314If 315.Nm 316receives a 317.Dv SIGINFO 318signal (see the 319.Cm status 320argument for 321.Xr stty 1 ) , 322the current transfer rate statistics will be written to the 323standard error output, in the same format as the standard completion 324message. 325.Sh ENVIRONMENT 326.Bl -tag -width HTTP_TIMEOUT 327.It Ev FTP_TIMEOUT 328Maximum time, in seconds, to wait before aborting an FTP connection. 329.It Ev HTTP_TIMEOUT 330Maximum time, in seconds, to wait before aborting an HTTP connection. 331.El 332.Pp 333See 334.Xr fetch 3 335for a description of additional environment variables, including 336.Ev FETCH_BIND_ADDRESS , 337.Ev FTP_LOGIN , 338.Ev FTP_PASSIVE_MODE , 339.Ev FTP_PASSWORD , 340.Ev FTP_PROXY , 341.Ev ftp_proxy , 342.Ev HTTP_AUTH , 343.Ev HTTP_PROXY , 344.Ev http_proxy , 345.Ev HTTP_PROXY_AUTH , 346.Ev HTTP_REFERER , 347.Ev HTTP_USER_AGENT , 348.Ev NETRC , 349.Ev NO_PROXY , 350.Ev no_proxy , 351.Ev SSL_ALLOW_SSL2 , 352.Ev SSL_CA_CERT_FILE , 353.Ev SSL_CA_CERT_PATH , 354.Ev SSL_CLIENT_CERT_FILE , 355.Ev SSL_CLIENT_KEY_FILE , 356.Ev SSL_CRL_FILE , 357.Ev SSL_NO_SSL3 , 358.Ev SSL_NO_TLS1 , 359.Ev SSL_NO_VERIFY_HOSTNAME 360and 361.Ev SSL_NO_VERIFY_PEER . 362.Sh EXIT STATUS 363The 364.Nm 365command returns zero on success, or one on failure. 366If multiple URLs are listed on the command line, 367.Nm 368will attempt to retrieve each one of them in turn, and will return 369zero only if they were all successfully retrieved. 370.Pp 371If the 372.Fl i 373argument is used and the remote file is not newer than the 374specified file then the command will still return success, 375although no file is transferred. 376.Sh SEE ALSO 377.Xr fetch 3 378.Sh HISTORY 379The 380.Nm 381command appeared in 382.Fx 2.1.5 . 383This implementation first appeared in 384.Fx 4.1 . 385.Sh AUTHORS 386.An -nosplit 387The original implementation of 388.Nm 389was done by 390.An Jean-Marc Zucconi Aq jmz@FreeBSD.org . 391It was extensively re-worked for 392.Fx 2.2 393by 394.An Garrett Wollman Aq wollman@FreeBSD.org , 395and later completely rewritten to use the 396.Xr fetch 3 397library by 398.An Dag-Erling Sm\(/orgrav Aq des@FreeBSD.org 399and 400.An Michael Gmelin Aq freebsd@grem.de . 401.Sh NOTES 402The 403.Fl b 404and 405.Fl t 406options are no longer supported and will generate warnings. 407They were workarounds for bugs in other OSes which this implementation 408does not trigger. 409.Pp 410One cannot both use the 411.Fl h , 412.Fl c 413and 414.Fl f 415options and specify URLs on the command line. 416