Creating a list from a relay in Python

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

This is my code:

import ftplib

files = []

my_ftp = ftplib.FTP(HOST)
my_ftp.login(USERNAME,PASSWORD)

line = my_ftp.retrlines("NLST",files.append(line))
my_ftp.quit()

      

The error says that the variable string is used before it is defined.

+3


source to share


2 answers


You probably just want to use nlst

:



>>> my_ftp.nlst()
['pub', 'etc', 'ports']

      

+7


source


Slight change in callback argument and the following should work



line = my_ftp.retrlines("NLST",files.append)

      

+4


source







All Articles