How to Upload a File to a Server via Ftp Using R

How to upload a file to a server via FTP using R?

This should work:

library(RCurl)
ftpUpload("Localfile.html", "ftp://User:Password@FTPServer/Destination.html")

Where Localfile.html is the file to be uploaded, User indicates the user name and Password the password to log into the server while FTPServer is a placeholder for the server name and possible path to use while last but not least Destination.html is an example of the name the to be uploaded file gets on the server.

How to push .csv file through FTP using R?

You don't have to use the read.csv() function.

ftpUpload('input/Anone_20190131185020.csv',
"ftp://103.X.X.X/ABCDHOSOLAR/",
userpwd = "login:password" )

Import File from FTP to R

I think you get this error message because function download.file() has no argument named credentials.

I would try to pass the credentials as discussed here:

url = "ftp://username:password@ftppath/www_logs/testfolder/test.csv"
download.file(url, destfile = "test.csv")

If you want to load the file into an R data.frame, you could try something like this:

library(RCurl) 
url <- "ftp://ftppath/www_logs/testfolder/test.csv"
text_data <- getURL(url, userpwd = "username:password", connecttimeout = 60)
df <- read.csv(text = text_data)

Using R to download newest files from ftp-server

This should work

library(RCurl)
url <- "ftp://yourServer"
userpwd <- "yourUser:yourPass"
filenames <- getURL(url, userpwd = userpwd,
ftp.use.epsv = FALSE,dirlistonly = TRUE)

-

times<-lapply(strsplit(filenames,"[-.]"),function(x){
time<-paste(c(substr(x[1], nchar(x[1])-3, nchar(x[1])),x[2:6]),
collapse="-")
time<-as.POSIXct(time, "%Y-%m-%d-%H-%M-%S", tz="GMT")
})
ind <- which.max(times)
dat <- try(getURL(paste(url,filenames[ind],sep=""), userpwd = userpwd))

So datis now containing the newest file

To make it reproduceable: all others can use this instead of the upper part use

filenames<-c("FileA2014-03-05-10-24-12.csv","FileB2014-03-06-10-25-12.csv") 


Related Topics



Leave a reply



Submit