How do you use Paramiko to transfer complete directories? I\'m trying to use:
sftp.put(\"/Folder1\",\"/Folder2\")
which is giving me this e
This can all be done quite easily using just paramiko.
A high level summary of the code below is:
- connect to the SFTP (steps 1 to 3)
- specify your source and target folders. (step 4)
- copy them over one by one to wherever you like (I've sent them to /tmp/). (step 5)
import paramiko
# 1 - Open a transport
host="your-host-name"
port = port_number
transport = paramiko.Transport((host, port))
# 2 - Auth
password="sftp_password"
username="sftp_username"
transport.connect(username = username, password = password)
# 3 - Go!
sftp = paramiko.SFTPClient.from_transport(transport)
# 4 - Specify your source and target folders.
source_folder="some/folder/path/on/sftp"
inbound_files=sftp.listdir(source_folder)
# 5 - Download all files from that path
for file in inbound_files :
filepath = source_folde+file
localpath = "/tmp/"+file
sftp.get(filepath, localpath)