【发布时间】:2020-04-22 15:34:21
【问题描述】:
基于这个问题 (Retrieve modified DateTime of a file from an FTP Server),很清楚如何获取日期修改值。但是,即使从 FTP 站点可以看到完整日期,也不会返回完整日期。
这显示了如何获取 ftp://ftp.FreeBSD.org/pub/FreeBSD/ 处文件的日期修改值
library(curl)
library(stringr)
con <- curl("ftp://ftp.FreeBSD.org/pub/FreeBSD/")
dat <- readLines(con)
close(con)
no_dirs <- grep("^d", dat, value=TRUE, invert=TRUE)
date_and_name <- sub("^[[:alnum:][:punct:][:blank:]]{43}", "", no_dirs)
dates <- sub('\\s[[:alpha:][:punct:][:alpha:]]+$', '', date_and_name)
dates
## [1] "May 07 2015" "Apr 22 15:15" "Apr 22 10:00"
有些日期采用月/日/年格式,其他日期采用月/日/小时/分钟格式。
查看 FTP 站点,所有日期均采用月/日/年时/分/秒格式。
我认为这与 Unix 格式标准有关(在 FTP details command doesn't seem to return the year the file was modified, is there a way around this? 中解释)。最好能得到完整的日期。
【问题讨论】:
标签: r web-scraping ftp