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 6206941
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T05:32:23+00:00 2026-05-24T05:32:23+00:00

I have an FTP function that traces the progress of running upload but my

  • 0

I have an FTP function that traces the progress of running upload but my understanding of threading is limited and i have been unable to implement a working solution… I’d like to add a GUI progress bar to my current Application by using threading. Can someone show me a basic function using asynchronous threads that can be updated from another running thread?

def ftpUploader():
    BLOCKSIZE = 57344 # size 56 kB

    ftp = ftplib.FTP()
    ftp.connect(host)
    ftp.login(login, passwd)
    ftp.voidcmd("TYPE I")
    f = open(zipname, 'rb')
    datasock, esize = ftp.ntransfercmd(
        'STOR %s' % os.path.basename(zipname))
    size = os.stat(zipname)[6]
    bytes_so_far = 0
    print 'started'
    while 1:
        buf = f.read(BLOCKSIZE)
        if not buf:
            break
        datasock.sendall(buf)
        bytes_so_far += len(buf)
        print "\rSent %d of %d bytes %.1f%%\r" % (
              bytes_so_far, size, 100 * bytes_so_far / size)
        sys.stdout.flush()

    datasock.close()
    f.close()
    ftp.voidresp()
    ftp.quit()
    print 'Complete...'
  • 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-05-24T05:32:24+00:00Added an answer on May 24, 2026 at 5:32 am

    Here’s a quick overview of threading, just in case 🙂 I won’t go into too much detail into the GUI stuff, other than to say that you should check out wxWidgets. Whenever you do something that takes a long time, like:

    from time import sleep
    for i in range(5):
        sleep(10)
    

    You’ll notice that to the user, the entire block of code seems to take 50 seconds. In those 5 seconds, your application can’t do anything like update the interface, and so it looks like it’s frozen. To solve this problem, we use threading.

    Usually there are two parts to this problem; the overall set of things you want to process, and the operation that takes a while, that we’d like to chop up. In this case, the overall set is the for loop and the operation we want chopped up is the sleep(10) function.

    Here’s a quick template for the threading code, based on our previous example. You should be able to work your code into this example.

    from threading import Thread
    from time import sleep
    
    # Threading.
    # The amount of seconds to wait before checking for an unpause condition.
    # Sleeping is necessary because if we don't, we'll block the os and make the
    # program look like it's frozen.
    PAUSE_SLEEP = 5
    
    # The number of iterations we want.
    TOTAL_ITERATIONS = 5
    
    class myThread(Thread):
        '''
        A thread used to do some stuff.
        '''
        def __init__(self, gui, otherStuff):
            '''
            Constructor. We pass in a reference to the GUI object we want
            to update here, as well as any other variables we want this
            thread to be aware of.
            '''
            # Construct the parent instance.
            Thread.__init__(self)
    
            # Store the gui, so that we can update it later.
            self.gui = gui
    
            # Store any other variables we want this thread to have access to.
            self.myStuff = otherStuff
    
            # Tracks the paused and stopped states of the thread.
            self.isPaused = False
            self.isStopped = False
    
        def pause(self):
            '''
            Called to pause the thread.
            '''
            self.isPaused = True
    
        def unpause(self):
            '''
            Called to unpause the thread.
            '''
            self.isPaused = False
    
        def stop(self):
            '''
            Called to stop the thread.
            '''
            self.isStopped = True
    
        def run(self):
            '''
            The main thread code.
            '''
            # The current iteration.
            currentIteration = 0
    
            # Keep going if the job is active.
            while self.isStopped == False:
                try:
                    # Check for a pause.
                    if self.isPaused:
                        # Sleep to let the os schedule other tasks.
                        sleep(PAUSE_SLEEP)
                        # Continue with the loop.
                        continue
    
                    # Check to see if we're still processing the set of
                    # things we want to do.
                    if currentIteration < TOTAL_ITERATIONS:
                        # Do the individual thing we want to do.
                        sleep(10)
                        # Update the count.
                        currentIteration += 1
                        # Update the gui.
                        self.gui.update(currentIteration,TOTAL_ITERATIONS)
                    else:
                        # Stop the loop.
                        self.isStopped = True
    
                except Exception as exception:
                    # If anything bad happens, report the error. It won't
                    # get written to stderr.
                    print exception
                    # Stop the loop.
                    self.isStopped = True
    
            # Tell the gui we're done.
            self.gui.stop()
    

    To call this thread, all you have to do is:

    aThread = myThread(myGui,myOtherStuff)
    aThread.start()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I created a function to download files from an FTP server that I have
We have a ftp system setup to monitor/download from remote ftp servers that are
I have response stream from a ftp web request that returns binary file. I
We have several cron jobs that ftp proxy logs to a centralized server. These
I have seen: http://www... ftp://blah.blah... file://blah.blah... unreal://blah.blah... mailto://blah.blah... What is that first section where
We have a C# application that connects to a FTP server, downloads some files,
I have some code that downloads a file from the internet located here: http://www.amsat.org/amsat/ftp/keps/current/nasa.all
I have been dealing with FTP lately and I'm not sure about the security
I have a webcam script that sends a JPG via FTP to my webserver
I have a php-script that uploads files to an ftp server from a location

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.