简体   繁体   English

python 3 ftp dir进入列表

[英]python 3 ftp dir into a list

the ftp site I am accessing doesn't support MLSD. 我正在访问的ftp站点不支持MLSD。 I can use nlst to get a list of files, but nlst() simply returns the name of the files instead of details that dir() displays 我可以使用nlst来获取文件列表,但是nlst()只是返回文件名而不是dir()显示的详细信息

ftpObj.dir()

drwxr-xr-x   2 ada      storage         0 Nov 12 00:38 Deltas
drwxr-xr-x   2 ada      storage         0 Nov 10 22:38 History

so, I tried a roundabout way (as recommended in another post): 因此,我尝试了一种回旋处的方式(如另一篇文章所建议):

data=[]
print(data.__len__())
data.append(ftpObj.dir())
print(data.__len__())

the output of the first print above is 0 and the output of the second print is 1. however, I am unable to access the information within data, ie if I try 上面第一张打印的输出为0,第二张打印的输出为1。但是,我无法访问数据中的信息,即如果我尝试

for line in data:
    print(line)

the output is 输出是

None

how can I see what is inside - data - above? 我怎样才能看到里面的数据-数据-上面的数据?

pass data.append as last argument to FTP.dir() , 将data.append作为最后一个参数传递给FTP.dir()

print(data.__len__())
ftpObj.dir(data.append)
print(data.__len__())

FTP.dir(argument[, ...]) FTP.dir(参数[,...])

Produce a directory listing as returned by the LIST command, printing it to standard output. 生成目录列表,如LIST命令所返回,将其打印到标准输出中。 The optional argument is a directory to list (default is the current server directory). 可选参数是要列出的目录(默认为当前服务器目录)。 Multiple arguments can be used to pass non-standard options to the LIST command. 可以使用多个参数将非标准选项传递给LIST命令。 If the last argument is a function, it is used as a callback function as for retrlines(); 如果最后一个参数是一个函数,则与retrlines()一样,将其用作回调函数。 the default prints to sys.stdout. 默认打印到sys.stdout。 This method returns None. 此方法返回无。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM