Python Forum

Full Version: Use pysftp to get the content of a remote folder
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I managed to get ssh working for me.

Now I want to log in, cd, get all the files in a directory, download them to /home/pedro/essays/ delete the files on the server and logout

The bit I'm not sure of: how to tell sftp where to download the files to??

Will this work?

Quote:remote_file = '*.* /home/pedro/essays/'

Also, what should go in hostname? The ip number or www.mywebpage.com?

import pysftp

hostname = '123.456.123.456'
me = 'mycPanelusername'
secret = 'mypassword'
remote_file = '*.* /home/pedro/essays/'

with pysftp.Connection('hostname', username='me', password='secret') as sftp:

    with sftp.cd('/public_html/php/uploads/'):           # temporarily chdir to /public_html/php/uploads/
        #sftp.put('/pycode/filename')  	# upload file to allcode/pycode on remote
        sftp.get('remote_file')         # get remote file(s)