Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8171723
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T21:32:50+00:00 2026-06-06T21:32:50+00:00

My program runs smoothly but I want my files from ftp to be zip

  • 0

My program runs smoothly but I want my files from ftp to be zip in my local drive

The problem is only 1 file is being zipped after calling my main() function

Here’s my code:

import os
import upload
import download
import zipfile
import ConfigParser
import ftputil

def main():
    
    #create a folder Temp on d drive for later use
    path = r'D:\Temp'
    os.mkdir(path)
    
    #parse all the  values at config.ini file
    config = ConfigParser.ConfigParser()
    config.readfp(open('config.ini'))
    server = config.get('main', 'Server')
    username = config.get('main', 'Username')
    password = config.get('main', 'Password')
    uploads = config.get('main', 'Upload folder')
    downloads = config.get('main', 'Download folder')

    #connect to ftp
    ftp = ftputil.FTPHost(server, username, password)

    dirlist = ftp.listdir(downloads)
    
    for list in dirlist:
        ftp.chdir(downloads)
        target = os.path.join(path, list)
        ftp.download(list, target)
        
    
    #########################################################
    #   THis section is where algo fails but the program run#
    ########################################################
    
    #zipping files
    absolute_path = r'D:\Temp'
    dirlist = os.listdir(absolute_path)
    filepath = r'D:\Temp\project2.zip'
    for list in dirlist:
        get_file = os.path.join(absolute_path, list)
        zip_name = zipfile.ZipFile(filepath, 'w')
        zip_name.write(get_file, 'Project2b\\' + list)
        
                
        

if __name__ == '__main__':
    print "cannot be"
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T21:32:51+00:00Added an answer on June 6, 2026 at 9:32 pm

    When you do this :

    for list in dirlist:
            get_file = os.path.join(absolute_path, list)
            zip_name = zipfile.ZipFile(filepath, 'w')
            zip_name.write(get_file, 'Project2b\\' + list)
    

    you recreate a ZipFile for each file you want to zip, the "w" mode means you recreate it from scratch.

    Try this (create the zip file before the loop) :

    zip_name = zipfile.ZipFile(filepath, 'w')
    for list in dirlist:
            get_file = os.path.join(absolute_path, list)
            zip_name.write(get_file, 'Project2b\\' + list)
    

    Or this, it will open the zipfile in append mode:

    for list in dirlist:
            get_file = os.path.join(absolute_path, list)
            zip_name = zipfile.ZipFile(filepath, 'a')
            zip_name.write(get_file, 'Project2b\\' + list)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When a user enters a whole number, the program runs smoothly, but when the
I have the below mail program. The problem is mail program runs successfully but
I've run into the following problem: My Delphi7 program runs smoothly on most computers
Following program runs fine with Netbeans IDE but when i try to run from
This program runs just fine, but for some reason when I ask for an
I have a class called ModelView which inherits from NSOpenGLView. When my program runs
I developed a model using Z3 .Net API. The program runs well. But when
I want a program that runs continually and monitors the time constantly. When it's
Every time my program runs vs adds the default configuration to my app.config file.
It seems at least weird to me... The program runs normally.But after I call

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.