Skip to content

Instantly share code, notes, and snippets.

@gnubyte
Forked from mariusavram91/copy_remote_files.py
Created August 1, 2018 14:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gnubyte/db85c8c8b48a65e919d89baaa8e844b7 to your computer and use it in GitHub Desktop.
Save gnubyte/db85c8c8b48a65e919d89baaa8e844b7 to your computer and use it in GitHub Desktop.
Copy remote files to local with Python's Paramiko
import os
import paramiko
paramiko.util.log_to_file('/tmp/paramiko.log')
paramiko.util.load_host_keys(os.path.expanduser('~/.ssh/known_hosts'))
host = 'local'
port = 22
username = 'user'
files = ['file1', 'file2', 'file3', 'file4']
remote_images_path = '/remote_path/images/'
local_path = '/tmp/'
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(
paramiko.AutoAddPolicy())
ssh.connect(hostname=host, port=port, username=username)
sftp = ssh.open_sftp()
for file in file:
file_remote = remote_images_path + file
file_local = local_path + file
print file_remote + '>>>' + file_local
sftp.get(file_remote, file_local)
sftp.close()
ssh.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment