1

I'm trying to download a zip file from an FTP link. I've tried to use request package but could not download

import requests
url = 'ftp://ftp.ibge.gov.br/Precos_Indices_de_Precos_ao_Consumidor/IPCA/Serie_Historica/ipca_SerieHist.zip'
r = requests.get(url)

Is there an easy way to download it? I can download it from the Chrome and don't need any type of login and password Thanks

1 Answers1

1

Please check this answer out: Python download zip files from a public FTP server The answer in that is below, credit to https://stackoverflow.com/users/4582273/lemonhead

url = urlparse.urlparse("ftp://ftp.ibge.gov.br/Precos_Indices_de_Precos_ao_Consumidor/IPCA/Serie_Historica/ipca_SerieHist.zip")
ftp = ftplib.FTP(url.netloc)
ftp.login()
ftp.cwd(ftp_dirname)
# Directory it will be downloaded to ^

with open(filename, 'w') as fobj:
    ftp.retrbinary('RETR %s' % basename, fobj.write)
Sheshank S.
  • 3,053
  • 3
  • 19
  • 39