I am trying to download a few zip files from a FTP site which requires credentials. I was able to get the list of files from the site using the getURL function in the RCurl pacakge. Here is the code I used (from the answer to one of the old stackoverflow questions).
library(RCurl)
url<-"ftp://ftp.mysite.com/EOD/"
userpwd<-"name:password"
filenames <- getURL(url, userpwd = userpwd,
ftp.use.epsv = FALSE,dirlistonly = TRUE)
filenames<-strsplit(filenames, "\r\n")
I have tried several functions (downloadFile, download.file, getURL, etc.) to download these files to a local directory on my computer however, I keep getting the error below-
Error in download.file(url, destfile = pathnameT, mode = mode, quiet = !isVisible(verbose), :
cannot open URL 'ftp://ftp.mysite.com/EOD/testfile_txt.zip'
In addition: Warning message:
In download.file(url, destfile = pathnameT, mode = mode, quiet = !isVisible(verbose), :
InternetOpenUrl failed: 'The login request was denied
After reading about this error, I tries two things- 1. specify setInternet2(use=TRUE) in downloadFile function; and 2. Uncheck "Use Internet Explorer library/proxy for HTTP" in global tools > Pacakages.
I'll appreciate if someone could help me with downloading these zipped files to a local directory using R. Thank you.
Interesting. I changed the argument ftp.use.epsv = FALSE
to ftp.use.epsv = TRUE
and worked fine.
Another change that make more organized the response:
from filenames<-strsplit(filenames, "\r\n")
to: filenames<-strsplit(filenames, "\n")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With