Creating list from retrlines in Python

前端 未结 2 408
余生分开走
余生分开走 2020-12-10 17:54

How exactly would you create a list of the entries in an FTP directory?

This is my code so far:

import ftplib

files = []

my_ftp = ftplib.FTP(HOST)
         


        
相关标签:
2条回答
  • 2020-12-10 18:43

    A little change to the callback argument and the following should work

    line = my_ftp.retrlines("NLST",files.append)
    
    0 讨论(0)
  • 2020-12-10 18:53

    You probably just want to use nlst:

    >>> my_ftp.nlst()
    ['pub', 'etc', 'ports']
    
    0 讨论(0)
提交回复
热议问题