Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
您将如何准确地创建 FTP 目录中的条目列表?
到目前为止,这是我的代码:
import ftplib files = [] my_ftp = ftplib.FTP(HOST) my_ftp.login(USERNAME,PASSWORD) line = my_ftp.retrlines("NLST",files.append(line)) my_ftp.quit()
该错误表示变量 line 在定义之前正在使用。
您可能只想使用nlst:
nlst
>>> my_ftp.nlst() ['pub', 'etc', 'ports']
对回调参数稍作改动,以下应该可以工作
line = my_ftp.retrlines("NLST",files.append)