我们要了解几个函数:

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

转载请注释:来自本地址

相关文章:

  • 2021-09-21
  • 2021-07-29
  • 2022-12-23
  • 2021-06-10
  • 2021-06-12
  • 2021-09-01
  • 2021-12-07
  • 2021-12-14
猜你喜欢
  • 2022-12-23
  • 2021-08-16
  • 2021-09-28
  • 2021-08-31
相关资源
相似解决方案