# -*- coding: utf-8 -*-
#! /usr/bin/python
import paramiko
import os
import time
import threading
import commands
import sys
master_running = True
agent_running = True
class SSHConnection(object):
def __init__(self, host_dict):
self.host = host_dict['host']
self.port = host_dict['port']
self.username = host_dict['username']
self.passwd = host_dict['passwd']
self.__k = None
def connect(self):
transport = paramiko.Transport((self.host, self.port))
transport.connect(username=self.username,password=self.passwd)
self.__transport = transport
def close(self):
self.__transport.close()
def run_cmd(self, command):
ssh = paramiko.SSHClient()
ssh._transport = self.__transport
stdin, stdout, stderr = ssh.exec_command(command)
# 获取命令结果
res = to_str(stdout.read())
# 获取错误信息
error = to_str(stderr.read())
# 如果有错误信息,返回error
# 否则返回res
if error.strip():
return False, error
else:
return True, res
def upload(self, local_path, target_path, exclude_args):
def put_file(lo_path, ta_path):
if not os.path.exists(lo_path):
print "%s is not exist" % lo_path
exit()
if os.path.isdir(lo_path):
self.run_cmd('mkdir %s' % ta_path)
file_list = os.listdir(lo_path)
for file in file_list:
if file in exclude_args:
continue
new_lo = lo_path + &
使用paramiko 进行多线程本地代码远端打包,及本地打总包
最新推荐文章于 2024-08-07 04:15:00 发布
本文介绍了如何利用Python的paramiko库进行多线程操作,实现本地代码的远端批量打包,并详细讲解了如何在本地进行打包结果的整合,为自动化部署提供高效解决方案。
摘要由CSDN通过智能技术生成