【问题标题】:Downloading .zip file from FTP in RStudio Cloud从 RStudio Cloud 中的 FTP 下载 .zip 文件
【发布时间】: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


    【解决方案1】:

    刚刚解决 - 如果有人可能正在寻找相同的原因,我只需点击路径选择上的选项卡:

    writeBin(raw,'hitTabWhenHere')
    

    然后选择了第一个选项 :) 至少文件现在在那里!

    【讨论】:

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