• ssh工具paramiko pyqt工具


    目录

    远程桌面工具:MobaXterm_Installer_v20.3.zip

    paramiko上传下载 并远程执行命令

    paramiko 远程命令:

    SSHTool


    远程桌面工具:MobaXterm_Installer_v20.3.zip

    百度网盘有,优点:左边是xftp,右边是命令行窗口

    xshell软件中,xftp和ssh命令窗口是分开的。

     

    paramiko上传下载 并远程执行命令

    1. import os
    2. import paramiko
    3. trans = paramiko.Transport(sock=("192.168.10.11", 220))
    4. trans.connect(username="root", password="root")
    5. sftp = paramiko.SFTPClient.from_transport(trans)
    6. def down_from_txt(txt_path,out_dir):
    7. with open(txt_path,'r') as f_r:
    8. lines=f_r.readlines()
    9. for data in lines:
    10. path=data.split(" ")[0]
    11. cls_index=data.split(" ")[1].replace("\n","")
    12. out_to=out_dir+cls_index
    13. file_name=os.path.basename(path)
    14. os.makedirs(out_to,exist_ok=True)
    15. sftp.get(path, out_to+'/'+ file_name)
    16. def get_ssh():
    17. ssh = paramiko.SSHClient()
    18. ssh._transport = trans
    19. return ssh
    20. def down_product():
    21. ssh=get_ssh()
    22. stdin, stdout, stderr = ssh.exec_command('cd data/demo && python3 demo.py')
    23. print(stdout.read().decode('utf-8'))
    24. ssh.close()
    25. def list_dir(dir_path='/data/demo/out'):
    26. ssh = get_ssh()
    27. stdin, stdout, stderr = ssh.exec_command(f'cd {dir_path} && ls')
    28. print(stdout.read().decode('utf-8'))
    29. ssh.close()
    30. if __name__ == '__main__':
    31. list_dir()
    32. #down_from_txt(r'D:\project\data\val_clf_sampler_demo.txt',r'D:\data\good_size/')
    33. # 上传
    34. # 把本地的文件settings.py,上传到远端为/root/Desktop/settings.py
    35. # sftp.put("settings.py" ,"/root/Desktop/settings.py")
    36. sftp.close()

    原文链接:https://blog.csdn.net/qq_39112101/article/details/94175083

    原文还有多线程应用


    paramiko 远程命令:


    原文链接:https://blog.csdn.net/weixin_45294285/article/details/122846537

    1. # encoding: utf-8
    2. import numpy as np
    3. import paramiko
    4. import time
    5. def creatSShConnectOb(hostname, username, password, port=22):
    6. ssh = paramiko.SSHClient()
    7. ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
    8. try:
    9. ssh.connect(hostname, port, username=username, password=password, timeout=60) # timeout protection
    10. return ssh
    11. except:
    12. print('Warning:\nFist connect the {} failed, now will retry!'.format(hostname))
    13. ssh.connect(hostname, port, username=username, password=password, timeout=60) # timeout re-try
    14. print('Error:\nAttempt to connect ABC failed!!! Please check the IP / port/ account / password.')
    15. def chanel_exe_cmd(ChanelSSHOb, cmd, t=0.1):
    16. ChanelSSHOb.send(cmd)
    17. ChanelSSHOb.send("\n")
    18. time.sleep(t)
    19. resp = ChanelSSHOb.recv(9999).decode("utf8")
    20. print("#"*40)
    21. return resp
    22. if __name__ == '__main__':
    23. ssh = creatSShConnectOb(hostname="192.168.110.16", username="root", password="xxx")
    24. chanelSSHOb = ssh.invoke_shell()
    25. result = chanel_exe_cmd(chanelSSHOb, "pwd")
    26. print(result)
    27. result = chanel_exe_cmd(chanelSSHOb, "cd /data")
    28. print(result)
    29. result = chanel_exe_cmd(chanelSSHOb, "pwd")
    30. print(result)

    SSHTool

    https://github.com/c0hb1rd/SSHTool

    https://github.com/movade005/pyqt-ssh-tool

  • 相关阅读:
    HTTP响应详解
    11-散列2 Hashing(浙大数据结构PTA习题)
    【JUC】ThreadPoolExecutor构造函数及拒绝策略
    C#性能优化-树形结构递归优化
    vue cli npm run build打生产环境包报错Cannot read property ‘pop‘ of undefined
    Elasticsearch学习-ES中的别名是什么
    负载均衡简介
    音视频技术开发周刊 | 315
    nginx服务---2
    leetcode(力扣) 343. 整数拆分 (动态规划 & 数学方法)
  • 原文地址:https://blog.csdn.net/jacke121/article/details/125535026