【问题标题】:Connection problem FTP using RCurl in R - specific folder在 R 特定文件夹中使用 RCurl 的连接问题 FTP
【发布时间】:2020-06-12 03:14:11
【问题描述】:

当我第一次启动 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)

返回此错误:

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)

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

任何想法为什么会发生这种情况? 我无法指定特定的文件夹或文件名,因为它每 30 分钟被覆盖一次并分配到每年/每月的文件夹中,因此我需要 *.his 立即工作。

提前致谢。

【问题讨论】:

  • 尝试使用“Sys.glob 扩展”,例如url &lt;- Sys.glob(file.path("ftp://12.34.56.78/Path/next/next", "*.his"))(见:stackoverflow.com/questions/17938916/sys-glob-expansion
  • 感谢您的回复。我试过了,但收到以下错误:函数错误(类型,味精,asError = TRUE):无法连接到 web-prdproxy-usr.dmz 端口 1080:超时
  • 您是否在使用代理?从错误的性质来看,似乎是这样。

标签: r ftp rcurl


【解决方案1】:

这就是我最终要做的。 我必须使用如下所示的日期格式创建一个动态 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)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-05-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多