파일 업로드에 사용할 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
반응형
'devlog > TIL' 카테고리의 다른 글
Transactional + DDD (0) | 2022.09.30 |
---|---|
[Gradle] gradle 빌드 OOM 발생할땐? (0) | 2022.09.20 |
[vim] 좀 더 편-안하게 vim editor를 사용하는 설정 (0) | 2020.10.07 |
[TIL] fluentd & NGINX (0) | 2020.09.22 |
뚝딱거리는 초보 devops의 TIL (0) | 2020.09.03 |