目录
paramiko:基于ssh连接远程服务器,可以完成远程上传和下载
1 window环境下连接Linux
def ssh_linux(command):
"""根据传入命令获取远程视频文件"""
# 创建一个ssh对象
client = paramiko.SSHClient()
# 自动选择yes,自动添加策略,保存服务器的主机名和密钥信息,如果不添加,那么不再本地know_hosts文件中记录的主机将无法连接
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
# 连接的服务器
client.connect(hostname="10.10.10.10",port=22,username="root",password="root")
# 执行操作
# 标准输入 标准正确输出 标准错误输出
stdin,stdout,stderr = client.exec_command(command) # 此处可以使用命令
# 获取命令的执行结果:stdout.read().decode('utf-8') #获取的为字符串
file_data = [one for one in stdout.read().decode('utf-8').split('\n') if 'mp4' in one]
# 关闭连接
client.close()
return file_data
command:为Linux下命令