RCurl::getURL 超出最大客户端数量

标签 r curl ftp rcurl

我正在尝试定期列出 MODIS 全局蒸散项目 (MOD16) 的 FTP 服务器上托管的文件。

## required package
library(RCurl)

## ftp server
ch_ftp <- "ftp://ftp.ntsg.umt.edu/pub/MODIS/NTSG_Products/MOD16/MOD16A2.105_MERRAGMAO/"

## list and reformat available subfolders
ch_fls <- getURL(ch_ftp, verbose = TRUE, dirlistonly = TRUE)

ls_fls <- strsplit(ch_fls, "\n")
ch_fls <- unlist(ls_fls)

## list files in current folder
for (i in ch_fls) {

  ch_hdf <- paste0(ch_ftp, i)
  getURL(ch_hdf, verbose = TRUE, dirlistonly = TRUE)
}

经过一些迭代后,RCurl::getURL 抛出以下错误消息。

< 530 Sorry, the maximum number of clients (5) from your host are already connected.
* Access denied: 530
* Closing connection 16
 Show Traceback

 Rerun with Debug
 Error in function (type, msg, asError = TRUE)  : Access denied: 530 

显然,RCurl::getURL 在每次迭代期间都会打开与 FTP 服务器的连接,但关闭速度不够快。几分钟后,服务器可以再次访问,但是在重新初始化脚本并等待前几次迭代时,将抛出相同的错误消息。有没有办法在检索文件列表后立即手动关闭由 RCurl::getURL 建立的连接?

最佳答案

我正在处理同样的问题。

使用 Sys.sleep(2) 为我解决了这个问题。

## list files in current folder
for (i in ch_fls) {

  ch_hdf <- paste0(ch_ftp, i)
  getURL(ch_hdf, verbose = TRUE, dirlistonly = TRUE)
  Sys.sleep(2)
}

关于RCurl::getURL 超出最大客户端数量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30888215/

相关文章:

r - igraph 有 "has_path"功能吗?

r - 在lattice的xyplot()中部分叠加数据

r - 按 block 创建索引序列

使用并行包删除僵尸进程

c# - 使用带有 C# REST API 和 SslStream 类的 cURL (PHP) 的 SSL/TLS 错误

c# - 远程服务器返回错误 : (421) Service not available, 关闭控制连接

php - PayPal IPN 无效进程

python - 如何使用 urllib3 在 Python 上发出 Post 请求?

ftp - 我怎样才能通过FTP访问centOS?

macos - Windows Azure 和 FileZilla FTP