Index: Doc/library/ftplib.rst =================================================================== --- Doc/library/ftplib.rst (revision 75198) +++ Doc/library/ftplib.rst (working copy) @@ -198,14 +198,15 @@ it is on by default.) -.. method:: FTP.storbinary(command, file[, blocksize, callback]) +.. method:: FTP.storbinary(command, file[, blocksize, callback, rest]) Store a file in binary transfer mode. *command* should be an appropriate ``STOR`` command: ``"STOR filename"``. *file* is an open file object which is read until EOF using its :meth:`read` method in blocks of size *blocksize* to provide the data to be stored. The *blocksize* argument defaults to 8192. *callback* is an optional single parameter callable that is called - on each block of data after it is sent. + on each block of data after it is sent. *rest* means the same thing as in + the :meth:`transfercmd` method. .. versionchanged:: 2.1 default for *blocksize* added. @@ -213,6 +214,8 @@ .. versionchanged:: 2.6 *callback* parameter added. + .. versionchanged:: 2.7 + *rest* parameter added. .. method:: FTP.storlines(command, file[, callback]) Index: Lib/ftplib.py =================================================================== --- Lib/ftplib.py (revision 75198) +++ Lib/ftplib.py (working copy) @@ -430,7 +430,7 @@ conn.close() return self.voidresp() - def storbinary(self, cmd, fp, blocksize=8192, callback=None): + def storbinary(self, cmd, fp, blocksize=8192, callback=None, rest=None): """Store a file in binary mode. A new port is created for you. Args: @@ -440,12 +440,13 @@ the connection at once. [default: 8192] callback: An optional single parameter callable that is called on on each block of data after it is sent. [default: None] + rest: Passed to transfercmd(). [default: None] Returns: The response code. """ self.voidcmd('TYPE I') - conn = self.transfercmd(cmd) + conn = self.transfercmd(cmd, rest) while 1: buf = fp.read(blocksize) if not buf: break Index: Lib/test/test_ftplib.py =================================================================== --- Lib/test/test_ftplib.py (revision 75198) +++ Lib/test/test_ftplib.py (working copy) @@ -46,6 +46,7 @@ self.last_received_cmd = None self.last_received_data = '' self.next_response = '' + self.rest = None self.push('220 welcome') def collect_incoming_data(self, data): @@ -159,10 +160,19 @@ def cmd_stor(self, arg): self.push('125 stor ok') + def cmd_rest(self, arg): + self.rest = arg + self.push('350 rest ok') + def cmd_retr(self, arg): self.push('125 retr ok') - self.dtp.push(RETR_DATA) + if self.rest is not None: + offset = int(self.rest) + else: + offset = 0 + self.dtp.push(RETR_DATA[offset:]) self.dtp.close_when_done() + self.rest = None def cmd_list(self, arg): self.push('125 list ok') @@ -314,6 +324,13 @@ received = [] self.client.retrbinary('retr', received.append) self.assertEqual(''.join(received), RETR_DATA) + for rest in (0, 10, 20): + received = [] + self.client.retrbinary('retr', received.append, rest=str(rest)) + self.assertEqual(''.join(received), RETR_DATA[rest:], + msg='rest test case %d %d %d' % (rest, + len(''.join(received)), + len(RETR_DATA[rest:]))) def test_retrlines(self): received = [] @@ -329,6 +346,10 @@ f.seek(0) self.client.storbinary('stor', f, callback=lambda x: flag.append(None)) self.assertTrue(flag) + # test rest + f.seek(0) + self.client.storbinary('stor', f, rest='30') + self.assertEqual(self.server.handler.rest, '30') def test_storlines(self): f = StringIO.StringIO(RETR_DATA.replace('\r\n', '\n'))