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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T02:16:18+00:00 2026-05-20T02:16:18+00:00

Trying to understand how the ftplib works. I am trying to save a file

  • 0

Trying to understand how the ftplib works.

I am trying to save a file to a FTP server and implement a callback.

The documentation says:

FTP.storbinary(command, file[, blocksize, callback, rest])

callback function is defined as in the documentation:

The callback function is called for
each block of data received, with a
single string argument giving the data
block.

How do I implement this callback? A sample callback on the retrbinary (reading a file) could look like:

def handle(block):
    f.write(block)
    print ".", 

Which will show the progress of the file being downloaded, f being the file object.

But I am at a loss on how to implement this with storbinary.

Any suggestions on how this can be done? I know about the block parameter, but how do I adjust it with the uploading?

UPDATE:

I have a callback for uploading as:

def handle(block):
    f.read(block)
    print ".",

But as expected, it gives the error:

an integer is required

Passing int(block) also doesn’t work.

  • 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-20T02:16:19+00:00Added an answer on May 20, 2026 at 2:16 am

    If your callback is

    def handle(block):
        f.write(block)
        print ".", 
    

    Python has first class functions that can be passed as params- this is the point of a callback- you you pass the function as param to the storbinary call-

    ftp.storbinary(command="stor someFileNameOnServer", file=open("localFile",'rb'), callback=handle,blocksize=1024)
    

    From the python doc,

    callback is an optional single parameter callable that is called on each block of data after it is sent.

    It’s purely a post-processing method for e.g. showing transfer status, it’s called after each block of data is sent. Above it would be called after sending every 1024 bytes of data.

    To implement transfer status, something like this-

    sizeWritten = 0
    totalSize = someMethodToGetTotalBytesInFile()
    def handle(block):
        global sizeWritten
        sizeWritten += 1024
        percentComplete = sizeWritten / totalSize
        print "%s percent complete" %str(sizeWritten / totalSize)
    

    os.path.getsize will give you the total size in bytes of your file.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Trying to understand something. I created a d:\svn\repository on my server. I committed folders
Im trying to understand how boolean logic works when I use NOT. To give
Trying to understand how EDE works by using it to generate Makefiles for a
Trying to understand, how to redirect program output to a file... Code : import
I'm trying understand how try ... catch construction works in T-SQL. So I've read
Trying to understand how CoffeeScript instance and class variable works I came with this
trying to understand how validation works in playframework1.2.4,I went through the docs and also
Trying to understand this open source app on github, it has a gem file:
HI Trying to understand how __radd__ works. I have the code >>> class X(object):
I am trying to download files from a ftp server but I am running

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.