加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Python > 正文

python – 在pysftp get中指定文件模式

发布时间:2020-12-16 22:59:01 所属栏目:Python 来源:网络整理
导读:我们可以写一个简单的得到这样的: import pysftphostname = "somehost"user = "bob" password = "123456" filename = 'somefile.txt'with pysftp.Connection(hostname,username=user,private_key='/home/private_key_file') as sftp: sftp.get(filename) 但
我们可以写一个简单的得到这样的:
import pysftp

hostname = "somehost"
user = "bob"       
password = "123456"  
filename = 'somefile.txt'

with pysftp.Connection(hostname,username=user,private_key='/home/private_key_file') as sftp:
    sftp.get(filename)

但是,我想在文件名中指定一个模式,例如:’* .txt’

有关如何使用pysftp执行此操作的任何想法?

解决方法

在pysftp中没有下载与文件掩码匹配的文件的功能.

你必须:

>使用listdirwalktree列出目录(如果需要递归)
>迭代文件列表,过滤所需的文件
>分别致电get.

有关灵感,请参阅如何实现get_dget_r(递归).

有关简单实现,请参阅List files on SFTP server matching wildcard in Python using Paramiko.有关递归示例,请参阅Python pysftp get_r from Linux works fine on Linux but not on Windows.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读