PHP API class connect to remote router

Hello all,

I’ve been trying out the RouterOS PHP API class to connect to my RB2011 router.

I have a ubuntu 12.04 LTS server that needs to connect to the router through this API. However, both the server and the router are on different networks.

How do I do this?

I have used this line of code so far:

<?php

require('routeros_api.class.php');

$API = new routeros_api();

$API->debug = true;

if ($API->connect('address', 'admin', 'password!')) {

   $API->write('/tool/fetch', false);
   $API->write('=address=address', false);
   $API->write('=src-path=file.conf', false);
   $API->write('=user=admin', false);
   $API->write('=mode=https', false);
   $API->write('=password=password!', false);
   $API->write('=dst-path=test.conf', false);
   $API->write('=port=443', false);
   $API->write('=keep-result=yes', false);
   
   $READ = $API->read(false);
   $ARRAY = $API->parse_response($READ);

   print_r($ARRAY);

   $API->disconnect();

}

?>

But when I execute this piece of code, it never stops loading the page. What am i doing wrong here?

I have used this PHP API: http://wiki.mikrotik.com/wiki/API_PHP_class

Forgot to remove the last ‘false’ boolean, works perfectly now :slight_smile:

I have added this line of code:

$API->write('/import config.rsc');

It seems like my code works fine as i get back this array:

/import config.rsc >>> [3/3] bytes read. >>> [3, 20]!re >>> [18/18] bytes read. >>> [18, 1]=status=connecting >>> [3/3] bytes read. >>> [3, 18]!re >>> [16/16] bytes read. >>> [16, 1]=status=finished Array ( [0] => Array ( [status] => connecting ) [1] => Array ( [status] => finished ) ) Disconnected...

However, changing the filename to something else that is not present in the /file directory doesn’t make a difference. It keeps showing the same array results.

Anyone know what I did wrong here?