New submission from Peter Pan:
When handling the transfer socket manually the asynchronous status message "226
transfer complete" on the control socket is falsely taken as response for the
last sent command.
ftplib reads the response too late and the command/response order becomes
invalid.
I can avoid that by using the undocumented ftplib internal method FTP.getline()
after the transfer socket is closed and not sending more commands while the
transfer socket is open.
It would be useful, if ftplib empties the response socket buffer before sending
the next command. But maybe the best solution is an optional function callback
when the "226" response appears, while it is ignored when not matching the last
sent command.
Example code that triggers the problem:
import ftplib
import socket
import re
ftp = ftplib.FTP()
ftp.set_debuglevel(1)
ftp.connect('ftp.debian.org', timeout=10)
ftp.login('anonymous','[email protected]')
ftp.sendcmd('TYPE A')
s = ftp.transfercmd('LIST')
'''
#manual transfer socket - should result in same behaviour
r = ftp.sendcmd('EPSV')
r = re.search('\|([0-9]+)\|', r)
port = int( r.group(1) )
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect(('ftp.debian.org', port))
ftp.sendcmd('LIST')
'''
fp = s.makefile('r')
fp.read()
fp.close()
s.close()
#ftplib falsely sees "226 transfer complete" as response to next command
ftp.sendcmd('NOOP')
----------
components: Library (Lib)
messages: 253326
nosy: peterpan
priority: normal
severity: normal
status: open
title: ftplib: command response shift - mismatch
type: behavior
versions: Python 3.4
_______________________________________
Python tracker <[email protected]>
<http://bugs.python.org/issue25458>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com