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 dat
is 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
Change the Color of the Axis Labels
Conditional 'Echo' (Or Eval or Include) in Rmarkdown Chunks
Difference Between Pull and Select in Dplyr
Filtering Data Frame Based on Na on Multiple Columns
Convert Scientific Notation to Numeric, Preserving Decimals
Adding Total/Subtotal to the Bottom of a Datatable in Shiny
How to Read CSV Data with Unknown Encoding in R
Order and Color of Bars in Ggplot2 Barplot
Order of Legend Entries in Ggplot2 Barplots with Coord_Flip()
Using Grep in R to Delete Rows from a Data.Frame
How to Set Unique Row and Column Names of a Matrix When Its Dimension Is Unknown
Ggplot2 Equivalent of Matplot():Plot a Matrix/Array by Columns
Automated Ggplot2 Example Gallery in Knitr
Building a Tiny R Package with Cuda and Rcpp
Ggplot2: Line Connecting the Means of Grouped Data
How to Set Attributes for a Variable in R