【问题标题】:How to write and then upload a graph to an FTP server using R?如何使用 R 编写图形然后将其上传到 FTP 服务器?
【发布时间】:2014-10-18 12:40:20
【问题描述】:

我在使用我的 R 脚本(RCurl 库)访问的 FTP 服务器上有一些文本文件。

x <- getURL(URL)
out <- read.csv(textConnection(x),header=FALSE,sep="")

之后,我从这些文件中提取必要的信息以生成 JPEG 格式的图形。

order_ID<-sub("order-Number:","",data[index_order_ID,])
jpeg(paste(order_ID,".jpeg"),quality=75,bg="white")

par(mfrow=c(2,2),mar=c(0.1,0.1,0.1,0.1),oma=c(0.1,0.1,0.1,0.1))

plot(c(-100:200),type="n",axes=TRUE,xlim=c(0,10),xaxt="n",yaxt="n",xlab="",ylab="")
rect(par("usr")[1], par("usr")[3], par("usr")[2], par("usr")[4], col = "gainsboro")
arrows(5,100,5,10,length=0.3,angle=40,lwd=10,col="darkgreen",code=2)
text(5,175,"Your Index:23",font=2,family="HersheySans",cex=1.2)

dev.off()

我打算将这个图上传/保存在 FTP 服务器的一个文件夹中,但是我不知道该怎么做?有什么办法可以避免将绘图保存到我的目录并直接将文件上传到服务器?

我尝试在 RCurl 中使用 ftpUpload() 函数。但是它给了我一条错误消息:

Uploading to a URL without a file name!

我将图表上传到服务器中的子文件夹而不是文件,所以我不知道如何解决这个错误。如果有人能告诉我哪里出错了,那将非常有帮助。谢谢。

【问题讨论】:

  • How to upload a file to a server via FTP using R? 的可能副本。该 SO 帖子显示了如何通过 RCurl 包使用 ftpUpload。您需要先保存绘图,然后上传,但可以使用?tempfile 创建名称。
  • 您可以将您尝试过的内容与错误消息一起添加到原始问题中。

标签: r plot ftp rcurl


【解决方案1】:

这对我有用!简单是最好的。享受吧!

require("RCurl")
library(httr)

# FTP settings
login<-"yourlogin"
secret<-"yourpassword"

uploadsite<-"ftp://yourwebsite.com/uploads"
uploadfilename<-"yourfile" # Sample only
yourlocalpngfilelocation<-"c:\\YourComputer\\YourLocalPNGfile.png"

ftpUpload(yourlocalpngfilelocation, 
paste(uploadsite,"/",uploadfilename,".png",sep=""),
userpwd=paste(login,secret,sep=":"))

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-04-06
    • 2018-09-27
    • 1970-01-01
    • 2011-09-25
    • 2014-10-17
    • 2017-07-26
    相关资源
    最近更新 更多