[英]export attempt in mikrotik with python
I am trying to export some files to my local pc with python, i tried several alternatives and i got several errors, but i got stuck on this error, couldn't find the cause, does anyone have any ideas?我正在尝试使用 python 将一些文件导出到我的本地电脑,我尝试了几种替代方法,但我遇到了几个错误,但我陷入了这个错误,找不到原因,有人有什么想法吗? I was seeing that it is entered by tftp, but I can't find a practical way to do it by code either
我看到它是通过 tftp 输入的,但我也找不到通过代码来实现的实用方法
My code:我的代码:
` `
import paramiko
from getpass import getpass
import time
HOST = 'xxx.xx.xx.xx'
PORT ='xx'
USER = 'xxx'
if __name__ == '__main__':
client = paramiko.SSHClient()
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
password = getpass ('Ingrese su contraseña: ')
client.connect(HOST, PORT, username=USER, password=password, banner_timeout=200)
stdin, stdout, stderr = client.exec_command('export file=/flash/prueba_export.backup to=C:/mikrotik')
time.sleep(1)
result = stdout.read().decode()
print(result)
error: expected end of command (line 1 column 41)
错误:
expected end of command (line 1 column 41)
Also try via tftpy:也可以通过 tftpy 尝试:
` `
import tftpy
# Crea un cliente TFTP
client = tftpy.TftpClient('ip', 69)
# Descarga el archivo de configuración de Mikrotik
client.download('flash/prueba_export.backup', 'C:\\mikrotik/prueba_export.backup')
# Cierra la conexión TFTP
client.close()
You can use the paramiko
library in unison with the python scp
library.您可以将
paramiko
库与 python scp
库结合使用。 It is very simple to use.使用起来非常简单。
install using: pip install scp
安装使用:
pip install scp
import paramiko
from scp import SCPClient
def sshClient():
# your paramiko code to connetc client
...
client.connect(HOST, PORT, username=USER, password=password)
return client
ssh = sshClient()
scp = SCPClient(ssh.get_transport())
Then simply use scp.get(...)
to download your wanted file.然后简单地使用
scp.get(...)
下载你想要的文件。
Also see scp's github page .另请参阅 scp 的github 页面。 You can also use with statements to make it cleaner:
您还可以使用 with 语句使其更清晰:
from paramiko import SSHClient
from scp import SCPClient
with SSHClient() as ssh:
ssh.load_system_host_keys()
ssh.connect('example.com')
with SCPClient(ssh.get_transport()) as scp:
scp.put('test.txt', 'test2.txt')
scp.get('test2.txt')
import paramiko
client = paramiko.SSHClient()
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
client.connect('ip', port='22', username='admin', password='pass')
#Setup sftp connection and transmit this script
print (client)
sftp = client.open_sftp()
sftp.get('/ruta_mikrotik','ruta_local')
sftp.close()
enter code here`
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.