华为交换机按下面需求的使用python写个脚本 # 保存配置文件并备份到本地
import paramiko
设置ssh连接信息
ssh = paramiko.SSHClient() ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) ssh.connect(hostname='switch_ip', port=22, username='username', password='password')
保存配置文件
stdin, stdout, stderr = ssh.exec_command('save') result = stdout.read().decode('utf-8')
备份配置文件到本地
sftp = ssh.open_sftp() sftp.get('/flash/config.text', 'config_backup.txt') sftp.close()
关闭ssh连接
ssh.close()
print('配置文件已保存并备份到本地!')
原文地址: https://www.cveoy.top/t/topic/fh0V 著作权归作者所有。请勿转载和采集!