Reputation: 649
I am trying to unzip the file located in my ftp server and download in a fly.
ftp=ftplib.FTP('myftplink')
ftp.login('username','password')
for filename in files_list:
os.chdir(dir)
local_file=os.path.join(os.getcwd(),filename)
ftp.retrbinary('RETR %s'%filename,open(filename,'wb').write)
with zipfile.ZipFile(filename,'r') as z:
z.extractall()
With this I could download the zip file and unzip it into the folder but is there a way to unzip and download only the unzipped file rather than download zip file.
Upvotes: 2
Views: 2693
Reputation: 2280
You will not be able to use this FTP library in python or FTP in general to unzip an archive. The unzipping has to happen either on the client side or on the server side. An informed decision as to where can be made after evaluating the size of the compressed archive that your program is attempting to download.
You will need access as well as privileges to run commands on the remote server, such as using SSH in order to uncompress there. If an SSH server is running on the remote host and you have access to it, you can use fabric to unzip the required file or run other commands on it before downloading your file via Fabric::put, SCP or FTP using the library you are currently using.
Upvotes: 3