0

I'm able to download a specific file from my SFTP server using the code below. I'm unable to download an entire folder. I'd like to simply copy the folder from the SFTP server to my local server. I do not want to copy all the files individually within the folder. I need to keep all of the contents of the folder tied to its specific folder. Here is my code below for simply downloading a file from my SFTP server. How can I download a folder from my SFTP server using Paramiko?

import paramiko


#create ssh client
ssh_client = paramiko.SSHClient()

#provide SFTP server details
server = "00.00.00.00"
port = 22
user = "MyUsername"
password = "MyPassword"

ssh_client.set_missing_host_key_policy(paramiko.AutoAddPolicy())

#connect to SFTP server and upload file
transport = paramiko.Transport((server, port))
transport.connect(username = user, password = password)

sftp = paramiko.SFTPClient.from_transport(transport)
sftp.get(remotepath=r'My Directory/My_File.txt', localpath=r'C:\Users\MyUsername\Documents\My_File.txt')
sftp.close()
transport.close()

print('Connection established and file(s) downloaded from SFTP server successfully')


I've been able to retrieve a unique file from SFTP server which works fine. I'd like to retrieve an entire folder

Ericander1
  • 11
  • 3

0 Answers0