Last active
June 4, 2023 11:14
-
-
Save mariusavram91/d84ce89645f5215a9c0b to your computer and use it in GitHub Desktop.
Copy remote files to local with Python's Paramiko
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 files: | |
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() |
Hi All,
Any script to copy files from local to remote system using Python's Paramiko
how to put directory to a remote location
How to download multiple files with like option(*) ?
abc.I*.today's date.input
wrong print command
Hey,
Thanks for this code, wanted to copy any file which start with some specific string, for example my sftp has serval projects files and all projects files are saved as project_number and some file name and extension, I want to loop all the files of same project number, can you please guide?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://lmgtfy.com/?q=paramiko+documentation+ssh+password