[ python-Bugs-1168983 ] ftplib.py string index out of range

SourceForge.net noreply at sourceforge.net
Thu Apr 7 11:51:28 CEST 2005


Bugs item #1168983, was opened at 2005-03-23 10:05
Message generated for change (Comment added) made by vmlinuxz
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1168983&group_id=5470

Category: Python Library
Group: Python 2.4
Status: Open
Resolution: None
Priority: 5
Submitted By: David Carroll (vmlinuxz)
Assigned to: Nobody/Anonymous (nobody)
Summary: ftplib.py string index out of range

Initial Comment:
The following code works great on all of the 2.3.x
releases I have used.

def
ftpFetch(localPath,remoteFileDate,ftpSite,ftpPass,ftpDir,ftpUser):
    print "Fetching split_mgr report"
    fileList=[]
    processList=[]
    ftp = FTP(ftpSite)
    ftp.login(ftpUser,ftpPass)               
    ftp.dir('LIST '+ftpDir,fileList.append)
    for x in range(len(fileList)):
        if (string.find(fileList[x],remoteFileDate) != -1):
            print fileList[x]
            TMP=fileList[x]
            output=localPath+str(TMP[45:])
            print output
            processList.append(output)
            print processList
            outfile = open(output,'w')
            ftp.retrbinary('RETR '+ftpDir+TMP[45:],
open(output, 'wb').write)
    ftp.quit()
    print processList
    return processList

However I get the following error under 2.4

Traceback (most recent call last):
  File
"C:\Python24\lib\site-packages\PythonCard\widget.py",
line 417, in _dispatch
    handler(background, aWxEvent)
  File "C:\Documents and
Settings\PROTECTED\Desktop\ReadWaitReport\ReadWaitReport\readwaitreport.py",
line 61, in on_btnRun_command
    mainRwclassLoop(self, mm+dd+yy, yesterday)
  File "C:\Documents and
Settings\PROTECTED\Desktop\ReadWaitReport\ReadWaitReport\rwclass.py",
line 39, in mainRwclassLoop
    processList =
ftpFetch(localPath,"split_mgr."+date[0:4],ftpSite,ftpPass,ftpDir,ftpUser)
  File "C:\Documents and
Settings\PROTECTED\Desktop\ReadWaitReport\ReadWaitReport\rwclass.py",
line 173, in ftpFetch
    ftp.dir('LIST '+ftpDir,fileList.append)
  File "C:\Python24\lib\ftplib.py", line 464, in dir
    self.retrlines(cmd, func)
  File "C:\Python24\lib\ftplib.py", line 396, in retrlines
    conn = self.transfercmd(cmd)
  File "C:\Python24\lib\ftplib.py", line 345, in
transfercmd
    return self.ntransfercmd(cmd, rest)[0]
  File "C:\Python24\lib\ftplib.py", line 328, in
ntransfercmd
    if resp[0] != '1':
IndexError: string index out of range

https://lists.dulug.duke.edu/pipermail/yum/2004-August/005067.html
discusses a similar problem under Linux in the YUM
script, I have reproduced this error under 2000, and XP.

I'm a fairly new programmer, and thus very new to
python so I hope this is enough information.  I will
try and keep track of this and help out with more
information in any capacity I can.

Thank you for all your hard work and dedication.
David Carroll

----------------------------------------------------------------------

>Comment By: David Carroll (vmlinuxz)
Date: 2005-04-07 09:51

Message:
Logged In: YES 
user_id=684143

Thank you for leaving this open.  I will try and get your
example today.  I'm too uneducated to realize what I'm doing
wrong, so maybe you can use my ignorance for the common good
=).  

----------------------------------------------------------------------

Comment By: Raymond Hettinger (rhettinger)
Date: 2005-04-05 04:31

Message:
Logged In: YES 
user_id=80475

I fixed the IndexError.  It should have been a protocol
error.  See Lib/ftplib.py  1.74.

Leaving the bug open so the OP can make a more detailed post
so we can see what the root issue is about.

----------------------------------------------------------------------

Comment By: Ilya Sandler (isandler)
Date: 2005-04-05 03:37

Message:
Logged In: YES 
user_id=971153

It turns out that the code in plain text bug report is more
or less readable, so I can see what you were trying to do...

Seems like you are doing 
  ftp.dir("LIST "+ftpDir)

But ftplib docs:
http://www.python.org/doc/current/lib/ftp-objects.html

say that you need to specify the directory
ftp.dir(ftpDir)

so it seems that you are using ftp.dir() incorrectly....

But, even then IndexError seems like a wrong kind of
exception for this kind of error...

So, I guess, my original request for a working code snippet
which would allow to reproduce the bug still stands..



----------------------------------------------------------------------

Comment By: Ilya Sandler (isandler)
Date: 2005-04-05 02:12

Message:
Logged In: YES 
user_id=971153


Could you submit a minimalistic piece of code which
illustrates the problem?
As well as any input data which are required to reproduce it?


(SourceForge garbled your original example)



----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1168983&group_id=5470


More information about the Python-bugs-list mailing list