Specify file pattern in pysftp get

Saurabh Verma picture Saurabh Verma · Mar 31, 2016 · Viewed 14.1k times · Source

We can write a simple get like this:

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)

However, I want to specify a pattern in the filename, something like: '*.txt'

Any idea on how to do this using pysftp ?

Answer

Martin Prikryl picture Martin Prikryl · Mar 31, 2016

There's no function to download files matching a file mask in pysftp.

You have to: