项目需求 -pyhton 在 linux 输入命令创建传输文件 1

项目需求 -pyhton 在 linux 输入命令创建传输文件 1

代码

#!/usr/bin/env Python3
# -*- coding: utf-8 -*-
# @Software: PyCharm
# @virtualenv:workon
# @contact: contact information
# @Desc:Code descripton
__author__ = '未昔/AngelFate'
__date__ = '2019/9/2 15:00'

import paramiko

# 创建SSHClient实例对象
ssh = paramiko.SSHClient()

ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())

ssh.connect(地址,端口,用户名,密码)

# 查询
cmd = 'ls'
stdin,stdout,stderr = ssh.exec_command(cmd)
print(stdout.read() + stderr.read())

cmd2 = 'mkdir paramiko2'
ssh.exec_command(cmd2)

cmd3 = 'cd paramiko'
ssh.exec_command(cmd3)

stdin2,stdout,stderr = ssh.exec_command(cmd)
print(stdout.read() + stderr.read())

结果

两个结果对比。明显多了一个文件

D:\import\python3.7\python.exe E:/python/Study/Python链接linux/class1.py

b'anaconda\nanaconda3\nAnaconda3-5.1.0-Linux-x86_64.sh\ndjango_blog\nhttp\nitchat.pkl\njupyter\njupyterhub_config.py\njupyterhub_cookie_secret\njupyterhub.log\njupyterhub-proxy.pid\njupyterhub.sqlite\nKeXie\nmyblog\nparamiko\nright.html\nrobot.py\nscript\nvirt-sysprep-firstboot.log\nwheels\nxadmin-django2.zip\n'

b'anaconda\nanaconda3\nAnaconda3-5.1.0-Linux-x86_64.sh\ndjango_blog\nhttp\nitchat.pkl\njupyter\njupyterhub_config.py\njupyterhub_cookie_secret\njupyterhub.log\njupyterhub-proxy.pid\njupyterhub.sqlite\nKeXie\nmyblog\nparamiko\nparamiko2\nright.html\nrobot.py\nscript\nvirt-sysprep-firstboot.log\nwheels\nxadmin-django2.zip\n'

Process finished with exit code 0

项目需求 -pyhton 在 linux 输入命令创建传输文件 1