List files on SFTP server matching wildcard in Python using Paramiko

无人久伴 提交于 2019-12-01 11:14:08

glob will not magically start working with a remote server, just because you have instantiated SSHClient before.

You have to use Paramiko API to list the files, like SFTPClient.listdir:

import fnmatch

sftp = client.open_sftp()

for filename in sftp.listdir('/home/test'):
    if fnmatch.fnmatch(filename, "*.txt"):
        print filename

Side note: Do not use AutoAddPolicy. You lose security by doing so. See Paramiko "Unknown Server".

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!