简体   繁体   English

使用 python 从 Mikrotik 提取备份

[英]Extract backups from Mikrotik with python

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.我必须使用 python 从 Mikrotik 提取备份并将它们保存在我的服务器中,以便这些备份保存在我的计算机和服务器上。 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)

You cannot do that with plain SSH. It will execute RouterOS commands (so no ls ).你不能用普通的 SSH 来做到这一点。它将执行 RouterOS 命令(所以没有ls )。 The task can be done with FTP or SFTP (if you prefer SSH) client:该任务可以使用 FTP 或 SFTP(如果您更喜欢 SSH)客户端完成:

$ 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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM