zoukankan      html  css  js  c++  java
  • 循环遍历共享文件夹,不需要知道目录深度拷贝上传

    # _*_ coding: utf-8 _*_
    __author__ = 'pythonwu'
    __date__ = "2018/8/21 17:10"

    import shutil
    import os
    import sys
    import paramiko
    from datetime import datetime


    hostname = 'xxx'
    username = 'xxx'
    password = 'xxx'
    port = 22

    def upload(local_dir,remote_dir):
    try:
    transport = paramiko.Transport(hostname,port)
    transport.connect(username=username,password=password)
    sftp = paramiko.SFTPClient.from_transport(transport)
    print('upload file start %s' %datetime.now())
    for root,dirs,files in os.walk(local_dir):
    for filespath in files:
    local_file = os.path.join(root,filespath)
    a = local_file.replace(local_dir,"")
    remote_file = os.path.join(remote_dir,a)
    remote_file_convert = remote_file.replace('\','/').replace('//','/')
    print(remote_file_convert)
    try:
    sftp.put(local_file,remote_file_convert)
    except Exception as e:
    repr(e)
    for name in dirs:
    local_path = os.path.join(root,name)
    a = local_path.replace(local_dir,"")
    remote_path = os.path.join(remote_dir,a)
    remote_path_convert = remote_path.replace('\','/').replace('//','/')
    print(remote_path_convert)
    try:
    sftp.mkdir(remote_path_convert)
    print("mkdir path %s" %remote_path_convert)
    except Exception as e:
    repr(e)
    print('upload file success %s' %datetime.now())
    transport.close()
    except Exception as e:
    repr(e)





    if __name__ == '__main__':
    local_dir = '\\tcent.cn\dfs\00.常用软件\17.IT专用软件\02.白名单软件库收集'
    remote_dir = '\\data\1'
    upload(local_dir,remote_dir)
  • 相关阅读:
    hdu 1045 Fire Net
    hdu 1044 Collect More Jewels
    hdu 1043 Eight
    hdu 1042 N!
    hdu 1041 Computer Transformation
    hdu 1040 As Easy As A+B
    CI在ngnix的配置
    angularjs表单验证checkbox
    chrome浏览器跨域设置
    angularjs向后台传参,后台收不到数据
  • 原文地址:https://www.cnblogs.com/wudeng/p/9519163.html
Copyright © 2011-2022 走看看