3

Want to download a csv-file from FTP-Server to R (it would be best to have the file as a dataframe in R).

Get an error-message when trying to download a csv-file from FTP-Server to R (which is local in my Mac).

url = "ftp://ftppath/www_logs/testfolder/"

download.file(URL,"test.csv", credentials = "xxx:yyyy")

Last query leads to:

Error in download.file(URL, "test.csv", credentials = "xxxyyy",  : 
unused arguments (credentials = "xxx:yyyy")
flobrr
  • 197
  • 1
  • 2
  • 13
  • 2
    In the documentation of the function `download.file()` I can not see a parameter `credentials=`. – jogo Jan 31 '19 at 12:22
  • you are right. my mistake, I mean 'download_ftp_file'. Found it here: [https://rdrr.io/github/skgrange/threadr/man/download_ftp_file.html]. My Problem now: Can not find a package with that function, even not with '?download_ftp_file' – flobrr Jan 31 '19 at 13:22
  • Try this solution: https://stackoverflow.com/a/45019200/6574038 – jay.sf Jan 31 '19 at 14:08
  • 1
    https://rdrr.io/github/skgrange/threadr/f/README.md – jogo Jan 31 '19 at 14:09

1 Answers1

6

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)
Franziska W.
  • 346
  • 2
  • 4
  • thx, but it results in message: `trying URL "ftp://username:password@ftppath/www_logs/testfolder/test.csv" Content type 'unknown' length 10 bytes`. Its a csv file with 1 columns and 3 rows with numbers from 1 to 3 – flobrr Jan 31 '19 at 13:34
  • Applying `url = ftp://username:password@ftppath/www_logs/testfolder/`results in message `trying URL '"ftp://username:password@ftppath/www_logs/testfolder/`. Ist this an error message? How can I transfer my download to an R-Objekt, e.g. in a `dataframe`? – flobrr Jan 31 '19 at 13:49
  • 1
    I edited my answer and hope the code works in your case. – Franziska W. Jan 31 '19 at 14:34
  • Hi Franziska, it nearly works perfectly and I state your response as "correct answer". One issue remains: the first row does not contain `1` but `1` in `df`. I also added `header = FALSE`, otherwise first row (value `1`) is excluded – flobrr Jan 31 '19 at 16:10