devlog/TIL
[Python] scp, paramiko 패키지 예제
bandal-gom
2021. 8. 26. 10:36
파일 업로드에 사용할 python 패키지를 찾다가 scp, paramiko를 사용하여 아래와 같이 개발함!
from paramiko import SSHClient
from scp import SCPClient
def upload_files(target, fileList):
scp = connect_to_server()
files = []
for file in fileList:
filename = file.rstrip()
file_full_path = "졀대/상대경로"+ filename
scp.put(files=filename, remote_path=file_full_path, recursive=True)
# fileList to
# scp.put(files=files, remote_path=target_path, recursive=True)
def connect_to_server():
ssh = SSHClient()
ssh.load_host_keys([ssh key 경로])
ssh.connect([서버주소], 22, 'centos', key_filename=[pem파일 경로])
scp = SCPClient(ssh.get_transport())
return scp
반응형