python 实现文件传输脚本

直接上传代码

 

# coding: utf-8
import paramiko
import os
import time

def file_transfer():
    start_time  = time.time()
    host = ''
    port = 22
    username = ''
    password = ''
    t = paramiko.Transport(host,port)
    t.connect(username=username, password=password)
    sftp = paramiko.SFTPClient.from_transport(t)

    #发送文件夹的位置
    bendiPath = "/home/data/bak/2020.zip"
    #接收文件夹的位置
    servicePath = '/home/xuchunlin/'
    print bendiPath
    print servicePath
    print time.time() - start_time
    #C_M_202101_392_HS.zip 是文件的名字
    sftp.put(bendiPath,os.path.join(servicePath, "C_M_202101_392_HS.zip"))
    t.close()
    print time.time() - start_time


if __name__ == '__main__':
    file_transfer()

 

posted @ 2021-03-29 08:48  淋哥  阅读(650)  评论(0编辑  收藏  举报