Download zip files from a link to a PC folder via R

Asked

Viewed 204 times

5

Good afternoon

I need to download the zip files from the following site

ftp://ftp.bmf.com.br/MarketData/

I would like to download via R, and that the files were saved on my computer, but I do not know command for such.

As there are many files, downloading them manually would be very time consuming.

Thanks in advance

1 answer

8


You can do so by using the package curl:

library(curl)
library(readr)

url_opcoes <- "ftp://ftp.bmf.com.br/MarketData/Bovespa-Opcoes/"
con <- curl(url_opcoes)
arquivos <- read_delim(con, delim = " ", col_names = FALSE)$X4

for (x in arquivos) 
  curl_download(url = paste0(url_opcoes, x), destfile = paste0("data/", x))

This code would download all the files that are in the Bovespa-Options directory of this FTP.

  • Thank you very much, solved the problem

  • 1

    There is a function list.files which lists all files within a folder. You can use it and then filter from the file array only those that are not in the folder.

  • thank you so much for your help

Browser other questions tagged

You are not signed in. Login or sign up in order to post.