测试

测试代码高亮

# encoding=UTF-8
import paramiko
class server(object):
    def __init__(self, ip='localhost', port=22, user='root', passwd='123456'):
        self.ip = ip
        self.port = port
        self.user = user
        self.passwd = passwd

        self.ssh = None
        self.sftp = None

    # 返回ssh连接和sftp连接
    def get_ssh_connection(self):
        transport = paramiko.Transport((self.ip, self.port))
        try:
            transport.connect(username=self.user, password=self.passwd)
        except Exception:
            return -1

        self.ssh = paramiko.SSHClient()
        self.ssh._transport = transport  # 将sftp和ssh一同建立
        self.sftp = paramiko.SFTPClient.from_transport(transport)

        return self.ssh, self.sftp

    def close_ssh_connection(self):
        self.ssh.close()
# 测试
上一篇:2021-01-27:如何把文件从服务器复制到本地,用什么命令?


下一篇:Linux sftp使用(持续更新)