yanpan
"""
@Time 2020/4/9 10:33
@Auth hzsyy
@File uploadFileToLinux.py
@IDE PyCharm

"""
import os

import paramiko


def uploadFileTolinux(reportFile, linuxPath, host, port):
file = reportFile.split("\\")[-1]
print(file)
private_key = paramiko.RSAKey.from_private_key_file(\'id_rsa\')
transport = paramiko.Transport((host, port))
transport.connect(username=\'root\', pkey=private_key)

sftp = paramiko.SFTPClient.from_transport(transport)
sftp.put(\'id_rsa\', os.path.join(f"/{linuxPath}/{file}")) # 上传本地文件至linux服务器
# sftp.get(r\'/服务器/1.txt\', r"本地\1.txt") # 下载服务器文件至本地

transport.close()
print("上传完成!")


if __name__ == "__main__":
reportFile = r"\Desktop\提测模块.xlsx"
linuxPath = "/home"
host = "100.100.90.38"
port = 22
uploadFileTolinux(reportFile, linuxPath, host, port)

分类:

技术点:

相关文章:

  • 2021-11-06
  • 2022-12-23
  • 2022-12-23
  • 2021-09-01
  • 2021-11-03
  • 2021-12-11
  • 2022-12-23
  • 2021-05-28
猜你喜欢
  • 2021-12-14
  • 2021-12-14
  • 2021-12-11
  • 2021-11-22
  • 2022-03-01
  • 2021-11-30
  • 2021-12-14
相关资源
相似解决方案