【问题标题】:Download .zip files from ftp R从 ftp R 下载 .zip 文件
【发布时间】:2016-03-09 04:55:00
【问题描述】:

我想下载所有这些文件,解压缩并导入到 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 

The data is found under this link

【问题讨论】:

    标签: r ftp zip rcurl


    【解决方案1】:

    尝试使用 wget 代替 curl:

    wget ftp://ftp.nrcan.gc.ca/pub/outgoing/canada_daily_grids/canada_daily1950.zip
    

    这将在您的计算机上下载其中一个文件,然后您可以编写一个 shell 脚本来遍历所有文件并解压缩它们。

    祝你好运!

    【讨论】:

      猜你喜欢
      • 2019-09-20
      • 2018-09-24
      • 1970-01-01
      • 1970-01-01
      • 2015-10-21
      • 2017-10-07
      • 2014-08-05
      • 1970-01-01
      相关资源
      最近更新 更多