title: Python - Download Zip File and Extract All
body: <p>I have two with block, one to download the zipped file and another one to extract all files. When I use them separately it works but when I use them together I receive an error saying BadZipFile. Here's an example of my code: </p>
  
  <pre><code>from ftplib import FTP
  import zipfile
  
  f = open(r'C:\file.zip', 'wb')
  
  with FTP("ftp.website.com") as ftp:
      ftp.login(user='USER', passwd='PASSWORD')
      ftp.retrbinary('RETR ' + 'file.zip', f.write, 1024)
  
  with zipfile.ZipFile('file.zip', 'r') as z:
      z.extractall()
  </code></pre>