I am downloading files from a password secured ftp. At home it works, but not at the Uni, where I need it, since I am using that computer for running scheduled tasks.
The code example is as follows (no using real names):
require("RCurl")
url_fore<- "ftp://xx.ftp./MET/"
local_fore <- "./data/ECMWF/"
file_fore <- try(getURL(url_fore, userpwd = userpwd,dirlistonly = TRUE, crlf=TRUE ))
file_fore <- unlist(str_extract_all(file_fore, ".+(.csv)"))
And I get the listing, but when trying to download files that do not exist locally I get an error.
I have found an example function online and adapted it for my case.
require("threadr")
downloadCSV <- function(filename, folder, baseurl) {
fileurl <- paste0(baseurl, filename)
if (!file.exists(str_c(folder, "/", filename))) {
download_ftp_file(fileurl,
paste0(folder, "/", filename),
credentials = userpwd)
Sys.sleep(1)
}
}
lapply(file_fore, function (x) downloadCSV(x, local_fore,url_fore))
Error in download.file(url, file_local, quiet = !verbose) :
cannot open URL 'ftp://xx.ftp.mu.ie/MET/FORECAST/some_file.csv' In addition: Warning message:
In download.file(url, file_local, quiet = !verbose) :
InternetOpenUrl failed: 'The login request was denied`
I have tried this, first solution did not help, and I did not know how to try second one, since that function is depreciated. Same question as mine here did not receive any answer.
Thanks...