diff -r 1ed74994c3e3 Lib/urllib.py --- a/Lib/urllib.py Fri Jun 24 11:39:57 2016 -0700 +++ b/Lib/urllib.py Sat Sep 17 18:22:58 2016 +0500 @@ -548,6 +548,8 @@ if not key in self.ftpcache: self.ftpcache[key] = \ ftpwrapper(user, passwd, host, port, dirs) + else: + self.ftpcache[key].clear_buffer() if not file: type = 'D' else: type = 'I' for attr in attrs: @@ -952,6 +954,13 @@ except ftperrors(): pass + def clear_buffer(self): + # Get pending responses from server if any + try: + self.ftp.getresp() + except ftperrors(): + pass + class addbase: """Base class for addinfo and addclosehook."""