【发布时间】:2019-09-20 23:03:22
【问题描述】:
问题
我正在尝试从 FTP 下载 .zip 文件,同时将其保存在云中并对其进行处理。
背景
由于公司原因,我无法在笔记本电脑上正确使用 R(旧版本、功能被阻止等)。我正在使用 RStudio Cloud 作为替代方案。
我正在使用 RCurl。根据我的发现,我需要运行 getBinaryURL 然后 writeBin,但我找不到将文件直接写入 RStudio Cloud 的方法。文件本身大约 150MB,RStudio Cloud 为每个项目分配 1GB 的 RAM,如果此信息相关的话。
install.packages("RCurl")
library("RCurl")
url <- "ftp://myftp"
userpwd <- "myuser:mypass"
filenames <- getURL(url, userpwd = userpwd,ftp.use.epsv = FALSE,dirlistonly = TRUE)
filenames
#All good up to here, files in FTP are returned
#I then had problems with the normal getURL, and found after some googling that I should use getBinaryURL
file<-"ftp://myftp/filename.zip"
con<-getCurlHandle(ftp.use.epsv=FALSE,userpwd=userpwd)
raw<-getBinaryURL(file,curl = con,dirlistonly=FALSE)
#This returns a raw file, 150MB
tmp<-tempfile()
zip<-writeBin(zip,tmp)
#Returns "Error in writeBin(zip, tmp) : can only write vector objects"
如何将 .zip 文件直接保存在云环境中?
注意:在普通笔记本电脑上我会使用命令
writeBin(zip,'directory/file.zip')
它可以正常工作
【问题讨论】:
标签: r ftp zip rcurl rstudio-server