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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T01:59:14+00:00 2026-05-27T01:59:14+00:00

I have looked everywhere and cannot find a fix for this problem, ftplib storbinary

  • 0

I have looked everywhere and cannot find a fix for this problem, ftplib storbinary callbacks.
This is my first time using callbacks so it could be something stupid, I have some code which should call my function everytime 8192 bytes are uploaded I assume (that’s how I think callbacks work after research).

#In main thread
def ftpcallback(intid):
    ftpuploaded = transStatus[intid][3] + 8192 #transStatus[intid] equals 0 to start with
    if ftpuploaded > transStatus[intid][2]: ftpuploaded = transStatus[intid][2] #Is this needed? It's supposed to just keep the value below the file size
    transStatus[intid][3] = ftpuploaded
    print (transStatus[intid][3]) #Always outputs 8192
    print("Callback called")

#Not in main thread
#FTP and file open code

self.ftp.storbinary("STOR " + self.destname, self.f, 1, ftpcallback(self.intid)) #1 to (hopefully) spam the output more

#close FTP and file code

Whenever that is run the callback only runs once, even for a 10MB file. What am I doing wrong?
Thanks in advance

  • 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-27T01:59:15+00:00Added an answer on May 27, 2026 at 1:59 am

    A callback, as it name suggests is when you tell some piece of code (ftplib) to call you back. What you did was to call the ftpcallback function yourself and pass it’s return value (which is None because it doesn’t return anything) to the storbinary method.

    Instead, you want to only pass the function object when calling storbinary and let ftplib call this function for you. You don’t want to call it yourself. Therefore, you need to get rid of the (...).

    intid = self.intid
    def ftpcallback():
        ftpuploaded = transStatus[intid][3] + 8192  # transStatus[intid] equals 0 to start with
        if ftpuploaded > transStatus[intid][2]:
            ftpuploaded = transStatus[intid][2]  # Is this needed? It's supposed to just keep the value below the file size
        transStatus[intid][3] = ftpuploaded
        print(transStatus[intid][3])  # Always outputs 8192
        print("Callback called")
    
    #FTP and file open code
    
    self.ftp.storbinary("STOR " + self.destname, self.f, 1, ftpcallback)
    

    The ftplib documentation doesn’t say anything about callback arguments so I assume it passes no arguments to the callback when it calls it. Your ftpcallback must therefore be callable as ftpcallback(), i.e. without arguments. That’s why I removed the intid argument and added intid = self.intid before the function.

    Another way to do it would be to define ftpcallback as a method (def ftpcallback(self):) of your class and pass self.ftpcallback to the storbinary call. Then you could simply use self.intid inside the method.

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

Sidebar

Related Questions

I have looked everywhere for the answer to this question, but cannot find anything
I have looked everywhere and surprisingly can't find a good solution to this! I've
So, I have looked everywhere for a solution to this problem I have and
I have looked pretty much everywhere but cannot seem to find an awnser to
I have looked everywhere but have not found a problem similar to this. I
I have looked everywhere but couldn't find it anywhere. I installed it successfully but
I have looked everywhere for the answer to this question and while there are
I have looked everywhere to find a linux utility that will allow me to
So I looked everywhere and I have no idea how to solve this certificate
(I looked everywhere for this, perhaps my googling skill is off today) I have

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.