Python Forum
Use pysftp to get the content of a remote folder - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Use pysftp to get the content of a remote folder (/thread-19209.html)



Use pysftp to get the content of a remote folder - Pedroski55 - Jun-18-2019

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)