python paramiko 进行文件上传处理
2024-09-17 13:55:47
#!/usr/bin/env python
# -*- coding:utf-8 -*-
import paramiko
import uuid
class Ha(object):
def __init__(self):
self.host = '192.168.1.101'
self.port = 22
self.username = 'root'
self.pwd = '' def crate_file(self):
file_name = str(uuid.uuid4())
with open(file_name ,'w') as f:
f.write('')
return file_name
def run(self):
self.connect()
self.Upload()
self.rname()
self.close()
def connect(self):
transport = paramiko.Transport((self.host, self.port))
transport.connect(username=self.username, password=self.pwd)
self.__transport = transport
def close(self):
self.__transport.close()
def Upload(self):
file_name = self.crate_file()
sftp = paramiko.SFTPClient.from_transport(self.__transport)
sftp.put(file_name, '/home/tttttttttttt.py')
def rname(self):
ssh = paramiko.SSHClient()
ssh._transport = self.__transport
stdin,stdout,stderr = ssh.exec_command('mv /home/tttttttttttt.py /home/1111111.py')
result = stdout.read() ha = Ha()
ha.run()
最新文章
- position:sticky的兼容性尝试
- OC与c混编实现Java的String的hashcode()函数
- myeclipse中的weblogic 服务未正常关闭问题解决。
- Linux System and Performance Monitoring
- CookieStore之Cookie的获取与保存
- linux重新设定分区大小
- [问题2015S06] 复旦高等代数 II(14级)每周一题(第七教学周)
- Jquery 知识表
- 继承(引用~析构~virtual)
- Android一 流
- (一)问候Spring4
- Swift Strings and Characters
- (转)linux中项目部署和日志查看
- DAY10、函数的参数
- Day7--------------IP地址配置
- vue项目中实现复制内容到剪贴板
- CDOJ 1960 构造哈密顿路径
- 【开发工具之eclipse】8、The word is not correctly spelled。强迫症看着很难受
- 《linux内核设计与实现》第三章
- WP8.1 页面跳转,overwrite后退键
热门文章
- 百度编辑器ueditor插入表格没有边框,没有颜色的解决方法 2015-01-06 09:24 98人阅读 评论(0) 收藏
- QTableView中修改某个单元格或者行或者列内容颜色
- Visual Studio 2008 Package Load Failure:未能正确加载包“Microsoft.VisualStudio.Xaml”
- 减少生成的dll数量
- C#学习笔记-封装
- Spring容器深入(li)
- 【http抓包】记录一次抓手机app的接口
- Lind.DDD.Domain领域模型介绍
- ASP.NET MVC导出excel(数据量大,非常耗时的,异步导出)
- java web学习总结(二) -------------------TOMCAT使用帮助(一)