ftplib question - ftp.dir() returns something and ftp.nlst() does not

Nico Grubert nicogrubert at gmail.com
Thu Nov 24 15:00:27 CET 2005


Hi there,

I am using the ftplib library to connect to a ftp server.
After I got connected, I can see a list of file in the current directory 
using ftp.dir() or ftp.retrlines('LIST'). But using ftp.nlst() returns 
an empty list which seems somehow strange to me. Here is, what I did:

 >>> from ftplib import FTP
 >>> HOST = 'my.server'
 >>> USER = 'myuser'
 >>> PASSWD = 'mypass'
 >>> ftp = FTP(HOST, USER, PASSWD)
 >>> ftp.set_pasv(0) # set active mode
 >>> ftp.dir()
-r--r--r--   1 owner    group          121984 Nov 24 12:13 member.dat
-r--r--r--   1 owner    group             115 Nov 24 15:53 status.dat
-r--r--r--   1 owner    group             339 Nov 24 15:53 debug.txt
 >>>
 >>> ftp.retrlines('LIST')
-r--r--r--   1 owner    group          121984 Nov 24 12:13 member.dat
-r--r--r--   1 owner    group             115 Nov 24 15:53 status.dat
-r--r--r--   1 owner    group             339 Nov 24 15:53 debug.txt
'226 Transfer complete.'
 >>>
 >>> ftp.nlst()
[]
 >>>

I thought "ftp.nlst()" would return the list ['member.dat', 
'status.dat', 'debug.txt']. Any idea, what is going wrong here?

Nico



More information about the Python-list mailing list