There's no way to make SFTPClient.listdir_attr
return a sorted list.
Sorting is easy though:
files = sftp.listdir_attr()
files.sort(key = lambda f: f.filename)
Or for example, if you want to sort only files by size from the largest to the smallest:
from stat import S_ISDIR, S_ISREG
files = [f for f in files if not S_ISDIR(f.st_mode)]
files.sort(key = lambda f: f.st_size, reverse = True)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…