I'm writing a module that uses FTPLib to fetch files. I want to find a way to pass a value(in addition to the block) to the callback. Essentially, my callback is
def handleDownload(block, fileToWrite):
fileToWrite.write(block)
And I need to call
ftp.retrbinary('RETR somefile', handleDownload)
And have it pass a file handle. Is there a way to do this?
You can close over the fileToWrite
variable with a lambda:
fileToWrite = open("somefile", "wb")
ftp.retrbinary("RETR somefile", lambda block: handleDownload(block, fileToWrite))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With