python 3.3 遍历服务器中的所有文件夹,用于FTP客户端文件夹的显示
#!/usr/bin/env python
import ftplib
f = ftplib.FTP()
f.connect("ip")
f.login("admin","admin")
path = []
def DirRecursive(root):
f.cwd(root)
ls = f.mlsd(root) # mlsd return generator object,is a tuple
for key in ls:
#print (key)
if key[1]['type'] == 'dir':
dirname = root + '/' + key[0]
path.append(dirname)
DirRecursive(dirname)
else:
pass
DirRecursive('/')
for pathname in path:
print (pathname)