首页 > 解决方案 > 在 Python Paramiko 中检索具有完整路径的目录中的文件列表

问题描述

我有这个代码使用本地文件:

path = r'/localhost_path/'

for filename in os.listdir(path):
    subpath = os.path.join(path, filename)
    if subpath.endswith('.txt'):
        print("TXT")

我试图用带有 Paramiko 的 SFTP 替换它,但它没有用。Paramiko 没有.join选择——如何解决这个问题?

标签: pythonsftpparamikoos.path

解决方案


如果您的问题是如何使用完整路径检索给定目录中的文件列表,您可以使用以下命令:

path = "/remote/path"
for filename in sftp.listdir(path):
    fullpath = path + "/" + filename
    print(fullpath)

推荐阅读