0

I have to extract backups from Mikrotik with python and save them in my server so these backups are saved in my computer and also on the servers. I've been searching for info about it but didn't have any luck. Can someone help me?

""" Authentication for remote desktops through ssh protocol  """

import paramiko
from getpass import getpass
import time

HOST = 'xxx.xxx.xxx.xxx'
PORT ='xxx'
USER = 'xxxxxxx'
""" data =dict(hostname=HOST, port=PORT, username=USER) """

if name == 'main':
    # try:
        client = paramiko.SSHClient()
        client.set_missing_host_key_policy( paramiko.AutoAddPolicy())

        password = getpass ('Insert password: ')
        client.connect(HOST, PORT, username=USER, password=password)

        stdin, stdout, stderr = client.exec_command('ls')

        #tried everything here

        time.sleep(1)

        result = stdout.read().decode()
    # except paramiko.ssh_exception.AuthenticationException as e:
    #     print('Failed authentication')

        print(result)
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. – Community Nov 21 '22 at 02:32

1 Answers1

0

You cannot do that with plain SSH. It will execute RouterOS commands (so no ls). The task can be done with FTP or SFTP (if you prefer SSH) client:

$ sftp admin@192.0.2.1
admin@192.0.2.1's password:
Connected to 192.0.2.1.
sftp> ls
flash
sftp> cd flash
sftp> ls
MikroTik-20210509-1756.backup   MikroTik-20210509-1938.backup   skins
sftp> get MikroTik-20210509-1756.backup
Fetching /flash/MikroTik-20210509-1756.backup to MikroTik-20210509-1756.backup
MikroTik-20210509-1756.backup                    100%  345KB 808.0KB/s   00:00
sftp> exit
Chupaka
  • 190
  • 6