zoukankan      html  css  js  c++  java
  • python paramiko 进行文件上传处理

     1 #!/usr/bin/env python
     2 # -*- coding:utf-8 -*-
     3 import paramiko
     4 import uuid
     5 class Ha(object):
     6     def __init__(self):
     7         self.host = '192.168.1.101'
     8         self.port = 22
     9         self.username = 'root'
    10         self.pwd = '123456'
    11 
    12     def crate_file(self):
    13         file_name = str(uuid.uuid4())
    14         with open(file_name ,'w') as f:
    15             f.write('11111')
    16         return file_name
    17     def run(self):
    18         self.connect()
    19         self.Upload()
    20         self.rname()
    21         self.close()
    22     def connect(self):
    23         transport = paramiko.Transport((self.host, self.port))
    24         transport.connect(username=self.username, password=self.pwd)
    25         self.__transport = transport
    26     def close(self):
    27         self.__transport.close()
    28     def Upload(self):
    29         file_name = self.crate_file()
    30         sftp = paramiko.SFTPClient.from_transport(self.__transport)
    31         sftp.put(file_name, '/home/tttttttttttt.py')
    32     def rname(self):
    33         ssh = paramiko.SSHClient()
    34         ssh._transport = self.__transport
    35         stdin,stdout,stderr = ssh.exec_command('mv /home/tttttttttttt.py /home/1111111.py')
    36         result = stdout.read()
    37 
    38 ha = Ha()
    39 ha.run()
  • 相关阅读:
    User-Introduction——介绍
    UserHow to Config
    DevHacking
    【转载】常备JS操作
    【转载】本地搜索服务全面评测
    User-Data config
    小知识:常用到的软件或服务及其使用的端口
    网页配色方案
    User-Validation User Guide
    Dev-Introduction
  • 原文地址:https://www.cnblogs.com/guigujun/p/6240132.html
Copyright © 2011-2022 走看看