Skip to content

Commit 03a9404

Browse files
committed
Fix SF bug #459767: ftplib fails with files > 2GB
size(), parse150(): try int() first, catch OverflowError, fall back to long().
1 parent 0197fe4 commit 03a9404

1 file changed

Lines changed: 13 additions & 5 deletions

File tree

Lib/ftplib.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,7 @@ def ntransfercmd(self, cmd, rest=None):
343343
return conn, size
344344

345345
def transfercmd(self, cmd, rest=None):
346-
"""Like nstransfercmd() but returns only the socket."""
346+
"""Like ntransfercmd() but returns only the socket."""
347347
return self.ntransfercmd(cmd, rest)[0]
348348

349349
def login(self, user = '', passwd = '', acct = ''):
@@ -505,7 +505,11 @@ def size(self, filename):
505505
# Note that the RFC doesn't say anything about 'SIZE'
506506
resp = self.sendcmd('SIZE ' + filename)
507507
if resp[:3] == '213':
508-
return int(resp[3:].strip())
508+
s = resp[3:].strip()
509+
try:
510+
return int(s)
511+
except OverflowError:
512+
return long(s)
509513

510514
def mkd(self, dirname):
511515
'''Make a directory, return its full pathname.'''
@@ -549,9 +553,13 @@ def parse150(resp):
549553
import re
550554
_150_re = re.compile("150 .* \((\d+) bytes\)", re.IGNORECASE)
551555
m = _150_re.match(resp)
552-
if m:
553-
return int(m.group(1))
554-
return None
556+
if not m:
557+
return None
558+
s = m.group(1)
559+
try:
560+
return int(s)
561+
except OverflowError:
562+
return long(s)
555563

556564

557565
_227_re = None

0 commit comments

Comments
 (0)