title: Using Python's ftplib to get a directory listing, portably
body: <p>You can use ftplib for full FTP support in Python. However the preferred way of getting a directory listing is:</p>
  
  <pre><code># File: ftplib-example-1.py
  
  import ftplib
  
  ftp = ftplib.FTP("www.python.org")
  ftp.login("anonymous", "ftplib-example-1")
  
  data = []
  
  ftp.dir(data.append)
  
  ftp.quit()
  
  for line in data:
      print "-", line
  </code></pre>
  
  <p>Which yields:</p>
  
  <pre><code>$ python ftplib-example-1.py
  - total 34
  - drwxrwxr-x  11 root     4127         512 Sep 14 14:18 .
  - drwxrwxr-x  11 root     4127         512 Sep 14 14:18 ..
  - drwxrwxr-x   2 root     4127         512 Sep 13 15:18 RCS
  - lrwxrwxrwx   1 root     bin           11 Jun 29 14:34 README -&gt; welcome.msg
  - drwxr-xr-x   3 root     wheel        512 May 19  1998 bin
  - drwxr-sr-x   3 root     1400         512 Jun  9  1997 dev
  - drwxrwxr--   2 root     4127         512 Feb  8  1998 dup
  - drwxr-xr-x   3 root     wheel        512 May 19  1998 etc
  ...
  </code></pre>
  
  <p>I guess the idea is to parse the results to get the directory listing. However this listing is directly dependent on the FTP server's way of formatting the list. It would be very messy to write code for this having to anticipate all the different ways FTP servers might format this list.</p>
  
  <p>Is there a portable way to get an array filled with the directory listing?</p>
  
  <p>(The array should only have the folder names.)</p>