Community discussions

MikroTik App
 
Ethan2126
just joined
Topic Author
Posts: 1
Joined: Fri Mar 19, 2021 3:55 pm

/tool fetch command using API issue

Fri Mar 19, 2021 4:24 pm

HI there,

Having an issue trying to use an API to issue a /tool fetch command and download a file. I am using a ccr1016 on 6.47.9.
My php script calls this API:
require('lib/routeros.class.php');

The code I am using currently is this:
$fileUrl = "http://".$localIP."/".$remoteSysModel."/".$fileName;
$remoteAPI->write('/tool fetch', false);
$remoteAPI->write('=url='.$fileUrl.'');

Also tried:
$remoteAPI->write('/tool fetch url='.$fileUrl.'');

Both of the above are unsuccessful nothing downloads. Any advice much appreciated.

The API is definitely connecting correctly because i retrieve info from the router using this commend $remoteAPI->comm('/system/routerboard/print'); earlier in the script.
The $fileUrl variable is correct as well and contains this string http://172.27.55.120/rb2011/routeros-verv-6.47.9.npk
Also if i run the command /tool fetch url=http://172.27.55.120/rb2011/routeros-verv-6.47.9.npk in the router cli through winbox, it works correctly and the file downloads.

Any help would be greatly appreciated.
Thanks in advance
 
elico
Member Candidate
Member Candidate
Posts: 143
Joined: Mon Nov 07, 2016 3:23 am

Re: /tool fetch command using API issue

Tue Mar 23, 2021 10:05 pm

You would need something like:
$fileUrl = "http://".$localIP."/".$remoteSysModel."/".$fileName;
$remoteAPI->write('/tool/fetch', false);
$remoteAPI->write('=url='.$fileUrl);

In api lines it should be something like:
/tool/fetch
=url=http://192.168.1.1/fileName
=dst-path=1

Who is online

Users browsing this forum: marcelofares and 24 guests