在 R 中使用 RCurl 的连接问题 FTP - 特定文件夹

Connection problem FTP using RCurl in R - specific folder

当我第一次启动 R Studio 时,我无法将以下代码获取到 运行。

library ("RCurl")

userpwd <- "User:Passwd"
tsfrFilename <- "/Path/*.his"    ### there is only one .his file in this pathway ###
ouptFilename <- "output.csv"

url <- "ftp://12.34.56.78/Path/*.his" 
data <- getURL(url = url, userpwd=userpwd)

Returns 这个错误:

Error in function (type, msg, asError = TRUE)  : RETR response: 550

但是,在指定了特定的路径和文件名(如下所示)之后,它就很有用了。 但是,当我随后使用上面的原始代码时,我可以毫无顾虑地连接并传输文件。

userpwd <- "User:Passwd"
tsfrFilename <- "/Path/next/next/name.his"
ouptFilename <- "output.csv"

url <- "ftp://12.34.56.78/Path/next/next/name.his" 
data <- getURL(url = url, userpwd=userpwd)

没有指定的原始代码 pathway/name 在我结束 R 会话之前一直有效,然后在重新启动时出现同样的问题。

知道为什么会这样吗? 我无法指定具体的文件夹或文件名,因为它每 30 分钟被覆盖一次并分配到每个 year/month 的文件夹中,因此我需要 *.his 立即工作。

提前致谢。

这就是我最终所做的。 我必须使用如下所示的日期格式创建一个动态 IP 地址。

# Get the date parts we need
Year <-format(Sys.Date(), format="%Y")
Month <- format(Sys.Date(), format="%B")
MM <- format(Sys.Date(), format="%m")

# Create the file string and read
emupark <- glue::glue("ftp://user:passwd@99.99.99.99/path/path/{Year}/{Month}/site}{Year}-{MM}.csv")
sitename<- read.csv(sitename, header = FALSE)