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

Question:

Good afternoon

I need to download the zip files from the following website

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

I would like to download via R, and that the files were saved on my computer, but I don't know the command to do so.

As there are a lot of files, downloading them manually would be very time consuming.

Thank you very much in advance

Answer:

You can do it like this, using the curl package:

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-Opcoes directory of that FTP.

Scroll to Top