Python Forum
Use pysftp to get the content of a remote folder
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Use pysftp to get the content of a remote folder
#1
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)
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Compare folder A and subfolder B and display files that are in folder A but not in su Melcu54 3 466 Jan-05-2024, 05:16 PM
Last Post: Pedroski55
  pysftp connection issue geil007 0 2,723 May-18-2022, 08:40 AM
Last Post: geil007
  Compare filename with folder name and copy matching files into a particular folder shantanu97 2 4,390 Dec-18-2021, 09:32 PM
Last Post: Larz60+
  Move file from one folder to another folder with timestamp added end of file shantanu97 0 2,436 Mar-22-2021, 10:59 AM
Last Post: shantanu97
  Python Cut/Copy paste file from folder to another folder rdDrp 4 4,944 Aug-19-2020, 12:40 PM
Last Post: rdDrp
  Does pysftp need a logout? Pedroski55 2 3,247 Jun-24-2019, 10:05 PM
Last Post: Pedroski55
  Delete directories in folder is not working after folder is updated asheru93 2 2,601 Feb-13-2019, 12:37 PM
Last Post: asheru93
  pysftp pop-up 'Client forking' micksulley 5 3,256 Dec-21-2018, 02:07 AM
Last Post: Larz60+
  copy content of folder to existing folder shlomi27 0 2,614 Aug-11-2018, 01:44 PM
Last Post: shlomi27
  PySFTP ChDir Error490 whoknows 2 3,897 Jan-19-2018, 08:18 PM
Last Post: whoknows

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020