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()
  • 相关阅读:
    Thinkcmf:页面常用函数
    thinkcmf开发--关于控制器
    thinkcmf 常用操作
    Thinkcmf 二次开发
    Sublime Text 3 快捷键精华版
    php动态更改post_max_size, upload_max_filesize等值
    Jquery使用小技巧
    jQuery常用方法和函数
    三层架构
    JDBC
  • 原文地址:https://www.cnblogs.com/guigujun/p/6240132.html
Copyright © 2011-2022 走看看