I am trying to download multiple files from a ftp. However, I get this error 
after downloading several files: cannot open URL ''. The stopage occurs 
randomly; can be after the 10th  or 30th etc. The code I am using is:
 
#########################
#rm(list=ls(all=TRUE))
require(RCurl)
require("R.utils")
ftp://ftp.root/ <- "ftp://ftp.cpc.ncep.noaa.gov/fews/AFR_CLIM/ARC2/DATA/1987/";
dropbox.root <- "H:/UNZIPPEDATA/"
 
#Function to download
 
fdownload <- function(sourcelink) { 
targetlink <- paste(dropbox.root, substr(sourcelink, nchar(ftp://ftp.root)+1/, 
nchar(sourcelink)), sep = '')
 
# list of contents of the files
  filenames <- getURL(sourcelink, ftp://ftp.use.epsv/ = FALSE, dirlistonly = 
TRUE)
  filenames <- strsplit(filenames, "\r\n*")
  filenames <- unlist(filenames)
  files <- filenames[grep('\\.', filenames)]  
  dirs <- setdiff(filenames, files)
  if (length(dirs) != 0) {
    dirs <- paste(sourcelink, dirs, '/', sep = '')
  }  
# Download files
  for (filename in files) {
    sourcefile <- paste(sourcelink, filename, sep = '')
    targetfile <- paste(targetlink, filename, sep = '')
    download.file(sourcefile, targetfile, cacheOK = TRUE, quiet = FALSE)
   
  }
# subfolders
  for (dirname in dirs) {
    fdownload(dirname)
  }
}
# Call the function
 
fdownload(ftp://ftp.root/)
 
###################################################### 

I could not find any solution from the web.

I will appreciate any help

Peter Maclean
Department of Economics
UDSM
        [[alternative HTML version deleted]]

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to