문제

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?

도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top