How to transfer a folder using Paramiko

I am trying to upload an 80 MB folder from a remote server to my local machine. I know that the file paths are correct, and I know that the folder exists. My current working code (works in a single file) is as follows:

import paramiko def begin(): tran=paramiko.Transport(('dns.server.name', 22)) tran.connect(username='**',password='**') sftp=paramiko.SFTPClient.from_transport(tran) sftp.get('/remote/file/path', '/local/file/path') sftp.close() tran.close() 

I tried adding sftp.listdir, but I am afraid that I cannot find enough documentation on this subject to make it clear or useful to me. Is there anything available similar to os.walk?

My question is: how to download small folders via ssh2 protocol available in paramiko?

+4
source share
1 answer

What I suggest instead of transferring the entire folder, you must first make a temporary compressed tar file on the server programmatically and transfer this tar file using sftp over the network - it can reduce bandwidh / will work faster and there will be less error prone.

+2
source

All Articles