Search code examples
pythonftpzip

Download zip file via FTP and extract files in memory in Python


I'm trying to download a zip file via ftp, but then extract the files inside without ever actually saving the zip. Any idea how I do this?


Solution

  • The ftplib module allows downloading files via FTP.

    The zipfile module allows extracting files from a zip file.

    Here's the key, the io.BytesIO class allows you to pass in-memory bytes to anything that expects a file. (In Python 2.x, the StringIO module provides similar functionality.)