I am writing a test harness in python and as part of the testing I need to initialise an FTP server and upload various files. I am using ftplib and everything is working ok. The only problem I have is that I am seeing loads of FTP text appearing in the console window intermixed with my test results, which makes scanning the results quite tricky. I haven't found a way to shut ftp lib up and stop this happening, does anyone know how to stop this?
+3
A:
You need to manually pass empty (or otherwise customized) callbacks to at least retrlines and dir. By default they print to stdout (questionable design). By default calls (probably for debugging) like
myFTP.retrlines(command)
myFTP.dir(someDir)
will print to your terminal. Remove them or use custom callbacks:
myFTP.retrlines(command, retrlinesCallback)
myFTP.dir(someDir, dirCallback)
retrlinesCallback
and dirCallback
functions could have logic to e.g. print to the terminal only if debugging is enabled.
There is also a set_debuglevel option. The default is 0 (no debugging), but it might be set higher somewhere in the code.
Matthew Flaschen
2010-06-10 13:20:36
Thanks for the response, I will try this now
JamieH
2010-06-10 13:37:43
This looks like the winner!
jathanism
2010-06-10 14:15:25