Search code examples
pythonparamikomikrotiktftp

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? I was seeing that it is entered by tftp, but I can't find a practical way to do it by code either

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)

Also try via 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()

Solution

  •     import paramiko
    
    client = paramiko.SSHClient()
    
    
    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`