我无法从外部ftp-source下载数据以便在shinyapp中使用。 http://Shinyapps.io不允许写入服务器上的文件,因此我们必须避免这种情况,并尝试使用ftp进行外部保存,然后再将其直接读入内存。
请参阅https://stackoverflow.com/a/32631356/3493503的Wes Sauder了解我的起点。
library(RCurl)
a <- "test"
saveRDS(a, file="data.Rdata")
data_path <- my_data_path
url <- my_ftp_url
ftpUpload(data_path, to=url, connecttimeout=120) #upload
bin = getBinaryURL(url, verbose = TRUE,
ftp.use.epsv = TRUE)
readRDS(rawConnection(bin))
上传工作正常,之后我可以用Filezilla下载文件并用readRDS读取。但是,尝试使用上面的代码在R中下载它不起作用:
> library(RCurl)
> a <- "test"
> saveRDS(a, file="data.Rdata")
> data_path <- "**************"
> url <-"ftp://******************/results.RData"
> ftpUpload(data_path, to=url, connecttimeout=120) #upload
OK
0
> bin = getBinaryURL(url, verbose = TRUE,
+ ftp.use.epsv = TRUE)
* Trying ***.***.***.***...
* Connected to ******************** port 21 (#0)
< 220---------- Welcome to Pure-FTPd [privsep] [TLS] ----------
< 220-You are user number 9 of 50 allowed.
< 220-Local time is now 10:43. Server port: 21.
< 220-This is a private system - No anonymous login
< 220-IPv6 connections are also welcome on this server.
< 220 You will be disconnected after 15 minutes of inactivity.
> USER ********
< 331 User ******** OK. Password required
> PASS ********
< 230 OK. Current restricted directory is /
> PWD
< 257 "/" is your current location
* Entry path is '/'
> EPSV
* Connect data stream passively
* ftp_perform ends with SECONDARY: 0
< 229 Extended Passive mode OK (|||31331|)
* Trying ********...
* Connecting to ******** port 31331
* Connected to ******** port 21 (#0)
> TYPE I
< 200 TYPE is now 8-bit binary
> SIZE results.RData
< 213 50
> RETR results.RData
< 150 Accepted data connection
* Maxdownload = -1
* Getting file with size: 50
* Remembering we are in dir ""
< 226-File successfully transferred
< 226 0.000 seconds (measured here), 0.66 Mbytes per second
* Connection #0 to host ******** left intact
> readRDS(rawConnection(bin))
Error in readRDS(rawConnection(bin)) : unknown input format
为了完整性,我也试过
load(rawConnection(bin))
Error in load(rawConnection(bin)) :
the input does not start with a magic number compatible with loading from a connection
source(rawConnection(bin))
Error in source(rawConnection(bin)) :
rawConnection(bin):1:1: unexpected input
1:
^
非常感谢任何解决方案/解释/输入。
我通过包含RDS对象的Filezilla上传了一个文件到http://webkartet.no/data.Rdata供您试用。它会导致同样的错误。
注意:我试图跟进Wes Sauders答案的评论部分,但未能这样做,显然是由于缺乏SE点。试图在SO上找到解决方案但没有成功。
其他信息
平台x86_64-w64-mingw32
拱x86_64
os mingw32
system x86_64,mingw32
状态
专业3 未成年人3.1
2016年年 月06
第21天 svn rev 70800
语言R
version.string R版本3.3.1(2016-06-21) 你头发中的昵称使用Windows 7