首页 > 编程语言 > 详细

python 使用paramiko模块上传本地文件到ssh

时间:2017-10-06 20:31:39      阅读:418      评论:0      收藏:0      [点我收藏+]

我们要了解几个函数:

paramiko.Tranport(("目标ip,端口"))#这是上传目标的IP和端口

  

paramiko.SFTPClient.from_tranport()#安全文件传输凭证

  

sftp.put(loaclfile,remotefile)#loaclfile是要上传的文件,remotefile是上传后要保存的文件名

  代码版:

import paramiko
ssh=paramiko.Transport(("192.168.223.129",22))
ssh.connect(username="root",password="root")
sftp=paramiko.SFTPClient.from_transport(ssh)
localfile="使用说明.txt"
remotefile="使用说明.txt"
try:
  sftp.put(localfile,remotefile)
except Exception:
    print("[-]put Error:User name or password error or uploaded file does not exist")


print("上传")
ssh.close()

成功图:

技术分享

转载请注释:来自本地址

python 使用paramiko模块上传本地文件到ssh

原文:http://www.cnblogs.com/haq5201314/p/7632561.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!