@@ -92,6 +92,7 @@ def __init__(self, conn):
9292 self .next_response = ''
9393 self .next_data = None
9494 self .rest = None
95+ self .next_retr_data = RETR_DATA
9596 self .push ('220 welcome' )
9697
9798 def collect_incoming_data (self , data ):
@@ -221,7 +222,7 @@ def cmd_retr(self, arg):
221222 offset = int (self .rest )
222223 else :
223224 offset = 0
224- self .dtp .push (RETR_DATA [offset :])
225+ self .dtp .push (self . next_retr_data [offset :])
225226 self .dtp .close_when_done ()
226227 self .rest = None
227228
@@ -243,6 +244,11 @@ def cmd_mlsd(self, arg):
243244 self .dtp .push (MLSD_DATA )
244245 self .dtp .close_when_done ()
245246
247+ def cmd_setlongretr (self , arg ):
248+ # For testing. Next RETR will return long line.
249+ self .next_retr_data = 'x' * int (arg )
250+ self .push ('125 setlongretr ok' )
251+
246252
247253class DummyFTPServer (asyncore .dispatcher , threading .Thread ):
248254
@@ -759,6 +765,20 @@ def test_parse257(self):
759765 self .assertEqual (ftplib .parse257 ('257 "/foo/b""ar"' ), '/foo/b"ar' )
760766 self .assertEqual (ftplib .parse257 ('257 "/foo/b""ar" created' ), '/foo/b"ar' )
761767
768+ def test_line_too_long (self ):
769+ self .assertRaises (ftplib .Error , self .client .sendcmd ,
770+ 'x' * self .client .maxline * 2 )
771+
772+ def test_retrlines_too_long (self ):
773+ self .client .sendcmd ('SETLONGRETR %d' % (self .client .maxline * 2 ))
774+ received = []
775+ self .assertRaises (ftplib .Error ,
776+ self .client .retrlines , 'retr' , received .append )
777+
778+ def test_storlines_too_long (self ):
779+ f = io .BytesIO (b'x' * self .client .maxline * 2 )
780+ self .assertRaises (ftplib .Error , self .client .storlines , 'stor' , f )
781+
762782
763783class TestIPv6Environment (TestCase ):
764784
0 commit comments