• php ssh2安装教程


    php ssh2安装教程

    下载地址 http://windows.php.net/downloads/pecl/releases/ssh2/0.12/

    根据自己PHP的版本去下载,我使用的是线程安全的,所以下载的是php_ssh2-0.12-5.4-ts-vc9-x86.zip

    将 php_ssh.dll、php_ssh2.pdb 放到你的 php 扩展目录下 php/ext/ 下

     php.ini中加入 extension=php_ssh2.dll

    我在centos下没问题 

    在win7下有问题 apache会崩掉

    所以我采用python ssh2 上传代码

    python上传目录的方法

    import paramiko
    import os
    ip='111';
    username='11';
    password='11';
    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(target_path1)
    copy_file(path,target_path1)
    else:
    path1 = os.path.join(target_path,file)
    sftp.put(path, path1)

    
    

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

    ssh.close()

    
    
    

     ps:如果出现no such file 那就创建目录后延迟后 再传输文件 或者 创建目录前先判断目录有没有存在 存在就不要创建了

  • 相关阅读:
    LeetCode 35 搜索插入位置
    LeetCode 69 x 的平方根
    LeetCode 61 旋转链表
    LeetCode 876 链表的中间结点
    LeetCode 142 环形链表 II
    LeetCode 206 反转链表
    LeetCode 237 删除链表中的节点
    LeetCode 83 删除排序链表中的重复元素
    元素的隐藏与显示与判断 js jquery aspx.cs
    判断对象是否为空 js与Jquery区别
  • 原文地址:https://www.cnblogs.com/newmiracle/p/13936923.html
Copyright © 2020-2023  润新知