我想下载所有这些文件,将它们解压缩并导入到R中,但多次尝试后下载失败。
以下是我尝试的代码(来自之前的帖子):
library(Rcurl)
url <- "ftp://ftp.nrcan.gc.ca/pub/outgoing/canada_daily_grids/"
protocol <- getURL(url,ftp.use.epsv=TRUE, dirlistonly=TRUE)
filenames <- protocol <- strsplit(protocol, "\r*\n")[[1]]
write.table(filenames, "names.txt", sep="\t")
zips <- sapply(filenames,function(x) substr(x,nchar(x)-2,nchar(x)))== "zip"
downloads <- filenames[zips]
con <- getCurlHandle(ftp.use.epsv = TRUE)
mapply(function(x,y) writeBin(getBinaryURL(x, curl = con, dirlistonly = FALSE), y), x = downloads, y = paste("C://dat/",downloads, sep = ""))
但我收到错误:
Error in function (type, msg, asError = TRUE) :
Failed to connect to ... port 80: Connection refused
答案 0 :(得分:2)
尝试使用wget而不是curl:
wget ftp://ftp.nrcan.gc.ca/pub/outgoing/canada_daily_grids/canada_daily1950.zip
这将下载您计算机上的一个文件,然后您可以编写一个shell脚本来遍历所有文件并解压缩它们。
祝你好运!