Rev 47482 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed
% File src/library/utils/man/download.file.Rd% Part of the R package, http://www.R-project.org% Copyright 1995-2009 R Core Development Team% Distributed under GPL 2 or later\name{download.file}\Rdversion{1.1}\alias{download.file}\concept{proxy}\concept{ftp}\concept{http}\title{Download File from the Internet}\description{This function can be used to download a file from the Internet.}\usage{download.file(url, destfile, method, quiet = FALSE, mode = "w",cacheOK = TRUE)}\arguments{\item{url}{A character string naming the URL of a resource to bedownloaded.}\item{destfile}{A character string with the name where the downloadedfile is saved. Tilde-expansion is performed.}\item{method}{Method to be used for downloading files. Currentlydownload methods \code{"internal"}, \code{"wget"} and \code{"lynx"}are available, and there is a value \code{"auto"}: see\sQuote{Details}. The method can also be set through the option\code{"download.file.method"}: see \code{\link{options}()}.}\item{quiet}{If \code{TRUE}, suppress status messages (if any), andthe progress bar.}\item{mode}{character. The mode with which to write the file. Usefulvalues are \code{"w"}, \code{"wb"} (binary), \code{"a"} (append) and\code{"ab"}. Only used for the \code{"internal"} method.#ifdef windows(See also \sQuote{Details}.)#endif}\item{cacheOK}{logical. Is a server-side cached value acceptable?Implemented for the \code{"internal"} and \code{"wget"} methods.}}\details{The function \code{download.file} can be used to download a singlefile as described by \code{url} from the internet and store it in\code{destfile}.The \code{url} must start with a scheme such as\code{"http://"}, \code{"ftp://"} or \code{"file://"}.#ifdef unixIf \code{method = "auto"} is chosen (the default), the internal methodis chosen for \code{"file://"} URLs, and for the others provided\code{\link{capabilities}("http/ftp")} is true (which it almost alwaysis). Otherwise methods \code{"wget"} and \code{"lynx"} are tried in turn.#endif#ifdef windowsIf \code{method = "auto"} is chosen (the default), the internal methodis used on Windows.#endif\code{cacheOK = FALSE} is useful for \code{"http://"} URLs, and willattempt to get a copy directly from the site rather than from anintermediate cache. (Not all platforms support it.)It is used by \code{\link{available.packages}}.The remaining details apply to method \code{"internal"} only.Note that \code{https://} connections are#ifdef unixnot supported.#endif#ifdef windowsonly supported if \code{--internet2} was used (to make use of InternetExplorer internals), and then only if the certificate is considered tobe valid.#endifSee \code{\link{url}} for how \code{"file://"} URLs are interpreted,especially on Windows. This function does decode encoded URLs.The timeout for many parts of the transfer can be set by the option\code{timeout} which defaults to 60 seconds.The level of detail provided during transfer can be set by the\code{quiet} argument and the \code{internet.info} option. Thedetails depend on the platform and scheme, but setting\code{internet.info} to 0 gives all available details, includingall server responses. Using 2 (the default) gives only seriousmessages, and 3 or more suppresses all messages.#ifdef windowsA progress bar tracks the transfer. If the file length is known, thefull width of the bar is the known length. Otherwise the initialwidth represents 100Kbytes and is doubled whenever the current widthis exceeded.If \code{mode} is not supplied and \code{url} ends in one of\code{.gz}, \code{.bz2}, \code{.tgz} or \code{.zip} a binary transferis done.There is an alternative method if you have Internet Explorer 4 orlater installed. You can use the flag \option{--internet2}, whenthe \sQuote{Internet Options} of the system are used to choose proxiesand so on; these are set in the Control Panel and are those used forInternet Explorer. This version does not support \code{cacheOK = FALSE}.#endif#ifdef unixA progress bar tracks the transfer. If the file length is known, anequals represents 2\% of the transfer completed: otherwise a dotrepresents 10Kb.#endifMethod \code{"wget"} can be used with proxy firewalls which requireuser/password authentication if proper values are stored in theconfiguration file for \code{wget}.}\note{Methods \code{"wget"} and \code{"lynx"} are for historicalcompatibility. They will block all other activity on the \R process.For methods \code{"wget"} and \code{"lynx"} a system call is made tothe tool given by \code{method}, and the respective program must beinstalled on your system and be in the search path for executables.}\section{Setting Proxies}{This applies to the internal code only.Proxies can be specified via environment variables.Setting \env{"no_proxy"} to \code{"*"} stops any proxy being tried.Otherwise the setting of \env{"http_proxy"} or \env{"ftp_proxy"}(or failing that, the all upper-case version) is consulted and ifnon-empty used as a proxy site. For FTP transfers, the usernameand password on the proxy can be specified by \env{"ftp_proxy_user"}and \env{"ftp_proxy_password"}. The form of \env{"http_proxy"}should be \code{"http://proxy.dom.com/"} or\code{"http://proxy.dom.com:8080/"} where the port defaults to\code{80} and the trailing slash may be omitted. For\env{"ftp_proxy"} use the form \code{"ftp://proxy.dom.com:3128/"}where the default port is \code{21}. These environment variablesmust be set before the download code is first used: they cannot bealtered later by calling \code{\link{Sys.setenv}}.Usernames and passwords can be set for HTTP proxy transfers viaenvironment variable \env{http_proxy_user} in the form\code{user:passwd}. Alternatively, \env{http_proxy} can be of theform \code{"http://user:pass@proxy.dom.com:8080/"} for compatibilitywith \code{wget}. Only the HTTP/1.0 basic authentication scheme issupported.#ifdef windowsUnder Windows, if \env{http_proxy_user} is set to \code{"ask"} thena dialog box will come up for the user to enter the username andpassword. \bold{NB:} you will be given only one opportunity to enter this,but if proxy authentication is required and fails there will be onefurther prompt per download.#endif}\value{An (invisible) integer code, \code{0} for success and non-zero forfailure. For the \code{"wget"} and \code{"lynx"} methods this is thestatus code returned by the external program. The \code{"internal"}method can return \code{1}, but will in most cases throw an error.}\seealso{\code{\link{options}} to set the \code{HTTPUserAgent}, \code{timeout}and \code{internet.info} options.\code{\link{url}} for a finer-grained way to read data from URLs.\code{\link{url.show}}, \code{\link{available.packages}},\code{\link{download.packages}} for applications.}\keyword{utilities}