[Python] scp, paramiko 패키지 예제

2021. 8. 26. 10:36·devlog/TIL

파일 업로드에 사용할 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

paramiko 문서 / 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
'devlog/TIL' 카테고리의 다른 글
  • Transactional + DDD
  • [Gradle] gradle 빌드 OOM 발생할땐?
  • [vim] 좀 더 편-안하게 vim editor를 사용하는 설정
  • [TIL] fluentd & NGINX
bandal-gom
bandal-gom
Devops & Backend Developer | tech blog
  • bandal-gom
    yayz's devlog
    bandal-gom
  • 전체
    오늘
    어제
    • 분류 전체보기 (68)
      • DevOps (22)
        • devops (4)
        • cicd (2)
        • docker (2)
        • monitoring (2)
        • nginx (4)
        • cache (1)
        • aws (1)
        • etc (6)
      • BE (21)
        • BE (3)
        • design pattern (1)
        • data structure (0)
        • spring (1)
        • algorithm (12)
      • devlog (24)
        • TIL (17)
        • programming language (2)
        • conference (2)
        • etc (3)
      • IT Review (1)
  • 블로그 메뉴

    • about.
    • 개발👩‍💻
    • etc.
  • 링크

    • Github
  • 공지사항

  • 인기 글

  • 태그

    코딩테스트준비
    leetcode 347
    time complexity
    항해99
    NGINX
    릿코드
    Python
    프로그래머스
    노트북하기좋은카페
    java
    티스토리챌린지
    젠킨스
    Programmers
    hash
    Kotlin
    문제풀이
    array
    algorithm
    오블완
    homelab
    LeetCode
    til
    개발자취업
    알고리즘문제풀이
    jenkins
    알고리즘
    모각코
    키캡
    키보드케이블
    99클럽
  • 최근 댓글

  • 최근 글

  • hELLO· Designed By정상우.v4.10.1
bandal-gom
[Python] scp, paramiko 패키지 예제
상단으로

티스토리툴바