0

I have some text files on an FTP server which I access using my R script(RCurl library).

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

Thereafter, I extract necessary information from these files to produce a graph in JPEG format.

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()

What I intend to do is to upload/save this plot in one of the folders of the FTP server, however I am not sure how should I go about this? Is there any way to avoid saving the plot to my directory and directly uploading the file to the server?

I have tried using ftpUpload() function in RCurl. However it gives me an error message:

Uploading to a URL without a file name!

I am uploading the graph to a sub-folder in the server and not a file, so I don't know how to work my way around this error. It will be very helpful if someone can tell me where I am going wrong. Thanks.

  • possible duplicate of [How to upload a file to a server via FTP using R?](http://stackoverflow.com/questions/3620426/how-to-upload-a-file-to-a-server-via-ftp-using-r). That SO post shows how to use `ftpUpload` via the `RCurl` package. You will need to do the plot save first, then upload but can use `?tempfile` to create the name. – hrbrmstr Oct 18 '14 at 12:43
  • You can add what you've tried to the original question along with the error message(s). – hrbrmstr Oct 20 '14 at 17:00

1 Answers1

0

This worked for me! Simple is best. Enjoy!

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=":"))