Dear list, I am trying to download a text file from an ftp site using download.file(). I used the following code: url <- "ftp://ftp.wcc.nrcs.usda.gov/data/snow/snow_course/table/history/idaho/13e19.txt" dest <- "c:/test/downloadtest.txt" download.file(url, dest) I get this error message, indicating that R is unable to open the connection: trying URL 'ftp://ftp.wcc.nrcs.usda.gov/data/snow/snow_course/table/history/idaho/13e19.txt' Error in download.file(url, dest) : cannot open URL 'ftp://ftp.wcc.nrcs.usda.gov/data/snow/snow_course/table/history/idaho/13e19.txt' I'm sure there is a simple solution that allows R to open this connection, but after reading the "url" help file for an hour, I can't seem to find the solution. Is anyone willing to help me solve this problem? thanks in advance for any advice, Zack
I ran your script on Windows Vista Ultimate, SP1 and it worked fine: ## R start...> url <- 'ftp://ftp.wcc.nrcs.usda.gov/data/snow/snow_course/table/history/idaho/13e19.txt' > dest <- "//PFO-SBS001/Redirected/tonyb/Desktop/test/downloadtest.txt" > download.file(url, dest)trying URL 'ftp://ftp.wcc.nrcs.usda.gov/data/snow/snow_course/table/ history/idaho/13e19.txt' ftp data connection made, file length 5026 bytes opened URL downloaded 5026 bytes ## R end.> sessionInfo()R version 2.8.1 (2008-12-22) i386-pc-mingw32 locale: LC_COLLATE=English_United Kingdom.1252;LC_CTYPE=English_United Kingdom. 1252;LC_MONETARY=English_United Kingdom. 1252;LC_NUMERIC=C;LC_TIME=English_United Kingdom.1252 attached base packages: [1] stats graphics grDevices utils datasets methods base>On 12 Jan, 14:51, zack holden <zack_hol... at hotmail.com> wrote:> Dear list, > > I am trying to download a text file from an ftp site using download.file(). > > I used the following code: > url <- "ftp://ftp.wcc.nrcs.usda.gov/data/snow/snow_course/table/history/idaho..." > dest <- "c:/test/downloadtest.txt" > download.file(url, dest) > I get this error message, indicating that R is unable to open the connection: > trying URL 'ftp://ftp.wcc.nrcs.usda.gov/data/snow/snow_course/table/history/idaho... > Error in download.file(url, dest) : > ? cannot open URL 'ftp://ftp.wcc.nrcs.usda.gov/data/snow/snow_course/table/history/idaho... > > I'm sure there is a simple solution that allows R to open this connection, but after reading the "url" help file for an hour, I can't seem to find the solution. Is anyone willing to help me solve this problem? > > thanks in advance for any advice, > > Zack > > ______________________________________________ > R-h... at r-project.org mailing listhttps://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guidehttp://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code.
First, try the example in the test file (tests/internet.R) read.table("ftp://ftp.stats.ox.ac.uk/pub/datasets/csb/ch11b.dat") or download.file("ftp://ftp.stats.ox.ac.uk/pub/datasets/csb/ch11b.dat", "test" That is known to work on many, many R systems. I get the same error as you on that URL, but it looks to me that the site required PASV ftp, something R's download.file does not support.>From the detailed logs (options(internet.info=0)<<< 230--------------------------------------------------------- 230- Welcome To The 230- Natural Resources Conservation Service - USDA 230- NATIONAL WATER and CLIMATE CENTER 230--------------------------------------------------------- 230- 230- The Local Date and Time is Mon Jan 12 08:30:25 2009 230- Current Directory is / 230- Information Contact is: info at wcc.nrcs.usda.gov 230- ----------------------------------------------------------- 230- Note that data files herein are at most updated once an hour. 230- 230 Guest login ok, access restrictions apply. -- 19: In download.file(url, dest) : --- -- 20: In download.file(url, dest) : Got 230 21: In download.file(url, dest) : Invalid answer to PASV Since you are on Windows, using --internet2 (see the rw-FAQ) might work. On Mon, 12 Jan 2009, zack holden wrote:> > Dear list, > > I am trying to download a text file from an ftp site using download.file(). > > I used the following code: > url <- "ftp://ftp.wcc.nrcs.usda.gov/data/snow/snow_course/table/history/idaho/13e19.txt" > dest <- "c:/test/downloadtest.txt" > download.file(url, dest) > I get this error message, indicating that R is unable to open the connection: > trying URL 'ftp://ftp.wcc.nrcs.usda.gov/data/snow/snow_course/table/history/idaho/13e19.txt' > Error in download.file(url, dest) : > cannot open URL 'ftp://ftp.wcc.nrcs.usda.gov/data/snow/snow_course/table/history/idaho/13e19.txt' > > I'm sure there is a simple solution that allows R to open this connection, but after reading the "url" help file for an hour, I can't seem to find the solution. Is anyone willing to help me solve this problem? > > thanks in advance for any advice, > > Zack-- Brian D. Ripley, ripley at stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UK Fax: +44 1865 272595