我有一些文件名为
FileA2014-03-05-10-24-12
FileB2014-03-06-10-25-12
其中“ 2014-03-05-10-24-12”部分表示“年/日/月/小时/小时/分钟/秒/”。这些文件位于ftp服务器上。我想使用R连接到ftp服务器并根据日期下载最新的文件。
我已经开始尝试使用RCurl和dirlistonly列出内容。下一步将尝试解析并找到最新文件。还不在那里...
library(RCurl)
getURL("ftpserver/",verbose=TRUE,dirlistonly = TRUE)
这应该工作
library(RCurl)
url <- "ftp://yourServer"
userpwd <- "yourUser:yourPass"
filenames <- getURL(url, userpwd = userpwd,
ftp.use.epsv = FALSE,dirlistonly = TRUE)
--
times<-lapply(strsplit(filenames,"[-.]"),function(x){
time<-paste(c(substr(x[1], nchar(x[1])-3, nchar(x[1])),x[2:6]),
collapse="-")
time<-as.POSIXct(time, "%Y-%m-%d-%H-%M-%S", tz="GMT")
})
ind <- which.max(times)
dat <- try(getURL(paste(url,filenames[ind],sep=""), userpwd = userpwd))
所以dat
现在包含最新文件
为了使其可重现:所有其他人都可以使用它而不是上半部分的用法
filenames<-c("FileA2014-03-05-10-24-12.csv","FileB2014-03-06-10-25-12.csv")
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句