def rcsv_listdir(self, sftp: paramiko.SFTPClient, path, dirs): if stat.S_ISREG(sftp.stat('.').st_mode): yield self.join_paths(sftp.getcwd(), sftp.stat('.').filename) sftp.chdir('..') return sftp.chdir(path) if not dirs: yield from (self.join_paths(sftp.getcwd(), fn) for fn in sftp.listdir('.')) sftp.chdir('..') return subdirs = sftp.listdir('.') if dirs[0] is None \ else set(sftp.listdir('.')).intersection(to_iter(dirs[0], ittype=iter)) for subdir in subdirs: yield from self.rcsv_listdir(sftp, subdir, dirs[1:]) sftp.chdir('..')