Created
October 12, 2022 07:01
Revisions
-
XiGou created this gist
Oct 12, 2022 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,32 @@ #! /bin/python3 # alternative for scp command import logging import paramiko class SSHClient: def __init__(self, host, user, psw) -> None: self.ssh = paramiko.SSHClient() self.ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) self.ssh.connect( host, username=user, password=psw, port=22, allow_agent=False, look_for_keys=False, ) def upload_file_to_dir(self, file, dir): sftp = self.ssh.open_sftp() sftp.put(file, dir) sftp.close() remode_dir = "/data/xxx" host = "x.x.x.x" user = "root" psw = "password" logging.basicConfig(level=logging.DEBUG) ssh = SSHClient(host, user, psw) local_filename = "xxx.py" ssh.upload_file_to_dir(local_filename, f"{remode_dir}/{local_filename}")