sftptransfer.py 文件源码

python
阅读 20 收藏 0 点赞 0 评论 0

项目:core-python 作者: yidao620c 项目源码 文件源码
def exe_command(hostname_, username_, password_, commandpaths_):
    ssh = paramiko.SSHClient()
    ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
    ssh.connect(hostname_, username=username_, password=password_)
    # channel = ssh.invoke_shell()
    # ssh_stdin, ssh_stdout, ssh_stderr = channel.exec_command(commandpath_)
    for command_ in commandpaths_:
        commandpath_, issudo = command_
        ssh_stdin, ssh_stdout, ssh_stderr = ssh.exec_command(commandpath_, get_pty=issudo)
        for eline in ssh_stdout.readlines():
            print('ssh_stdout:{}'.format(eline), end='')
        for eline in ssh_stderr.readlines():
            print('ssh_stderr:{}'.format(eline), end='')
        # Cleanup
        ssh_stdin.close()
        ssh_stdout.close()
        ssh_stderr.close()
    # channel.close()
    ssh.close()
    LOG.info('end successfully!')
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号