zoukankan      html  css  js  c++  java
  • python远程创建文件夹上传文件

    python远程创建文件夹上传文件

     这里注意 路径/一定要完整 不然 os.path.join 默认都是链接路径的

    import paramiko
    import os
    ip='1121';
    username='12';
    password='32333';
    transport = paramiko.Transport((ip, 22))
    transport.connect(username=username, password=password)
    sftp = paramiko.SFTPClient.from_transport(transport)
    ssh = paramiko.SSHClient();

    ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
    ssh.connect(hostname=ip, port=22, username=username, password=password)

    #上传文件目录
    src_path = 'C:/Users/Administrator/Desktop/ss'
    target_path ='/root/ss'
    ssh.exec_command('mkdir -p '+target_path);
    def copy_file(src_path,target_path):
    src_path=src_path+'/';
    target_path=target_path+'/';
    filelist = os.listdir(src_path)
    for file in filelist:
    path = os.path.join(src_path,file)
    if os.path.isdir(path):
    # 递归调用
    target_path1 = os.path.join(target_path,file)
    ssh.exec_command('mkdir -p '+target_path1)
    print('pathx '+path)
    print('target_path1 '+target_path1)
    copy_file(path,target_path1)
    else:
    path1 = os.path.join(target_path,file)
    print('pathxx '+path)
    print('path1 '+path1)
    sftp.put(path, path1)

    copy_file(src_path,target_path)
    transport.close();

  • 相关阅读:
    新启发:Relu与dropout的联系
    神经网络之各种激活函数
    Relu激活函数的死神经元问题
    1.openshift搭建
    1.promethues监控融入k8s
    内部yum仓库制作
    python可迭代对象和迭代器和生成器
    python3基本数据类型
    python3的字符串和字节
    2.nginx_rewrite模块
  • 原文地址:https://www.cnblogs.com/newmiracle/p/13941834.html
Copyright © 2011-2022 走看看