windows上传文件至服务器

2021-03-10 22:33

阅读:499

标签:服务器   模块   sftp   client   cli   connect   let   color   adf   

"""
@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)

windows上传文件至服务器

标签:服务器   模块   sftp   client   cli   connect   let   color   adf   

原文地址:https://www.cnblogs.com/yanpan/p/12665880.html


评论


亲,登录后才可以留言!