如何直接从FTP服务器下载文件到R / RStudio?

时间:2019-07-02 15:45:02

标签: r

我正在尝试将文件从FTP服务器直接下载到R会话中,但到目前为止还无法完成,我的所有尝试都是通过RCurl或utils软件包进行的。

我已成功连接到服务器,并且我知道这是因为包含在下面的代码段中的“文件名”对象会返回我FTP目录中的所有文件夹/文件。

library(RCurl)

### First try

userpwd <- "user"
url <- "ftp://xx.xx.xxx.xxx/"

fileNames <- getURL(url = url,
                    userpwd = userpwd,
                    ftp.use.epsv = FALSE,
                    dirlistonly = TRUE)

fileNames <- paste(url,
                   strsplit(fileNames, "\r*\n")[[1]],
                   sep = "")

con <- getCurlHandle(ftp.use.epsv = FALSE, userpwd = userpwd)
contents = sapply(fileNames[1],
                  function(x) try(getURL(x, curl = con)))

### Second try

getURL(paste(url,fileNames[[1]][1],sep=""), userpwd = userpwd)

### Third try

download.file(url = getURL(paste(url,fileNames[[1]][2],sep=""),
              userpwd = userpwd))

这是我第一次从R会话中收到的消息:

“ curlPerform中的错误(curl = curl,.opts = opts,.encoding = .encoding):   字符串中嵌入nul“

第二个还给我这个:

“函数错误(类型,msg,asError = TRUE):   服务器拒绝您更改到给定目录“

第三个人给我以下信息:

“函数中的错误(类型,msg,asError = TRUE):RETR响应:550”

您能帮我发现代码中的任何问题还是给我一些建议的程序包/代码吗?

0 个答案:

没有答案