Pass ftp.retrbinary callback value

I am writing a module that uses FTPLib to extract files. I want to find a way to pass a value (in addition to a block) to a callback. Essentially my callback

def handleDownload(block, fileToWrite): fileToWrite.write(block) 

And I need to call

 ftp.retrbinary('RETR somefile', handleDownload) 

And let it pass the file descriptor. Is there any way to do this?

+6
source share
1 answer

You can close the fileToWrite variable with lambda :

 fileToWrite = open("somefile", "wb") ftp.retrbinary("RETR somefile", lambda block: handleDownload(block, fileToWrite)) 
+5
source

Source: https://habr.com/ru/post/923411/


All Articles