Fetch
Fetch is a RouterOS console utility for copying files and performing HTTP-based requests. It works with HTTP, HTTPS, FTP, TFTP and SFTP, allowing uploads, downloads, and arbitrary GET or POST operations to remote servers.
All parameters are documented in the /tool/fetch CLI reference.
Configuration examples
The following example shows how to copy the file "conf.rsc" from a device with IP address 192.168.88.2 by FTP protocol and save it as "123.rsc". User and password are needed to log in to the device.
[admin@MikroTik] /tool> fetch address=192.168.88.2 src-path=conf.rsc user=admin mode=ftp password=123 dst-path=123.rsc port=21 host="" keep-result=yes
Example to upload a file to another router:
[admin@MikroTik] /tool> fetch address=192.168.88.2 src-path=conf.rsc user=admin mode=ftp password=123 dst-path=123.rsc upload=yes
Another file download example that demonstrates the usage of the url property:
[admin@MikroTik] /> /tool/fetch url="https://www.mikrotik.com/img/netaddresses2.pdf" mode=http
status: finished
[admin@test_host] /> /file/print
# NAME TYPE SIZE CREATION-TIME
...
5 netaddresses2.pdf .pdf file 11547 2010-06-01 11:59:51
Running fetch through a VRF
You can run /tool/fetch through a specific VRF by appending the VRF name after an "@" symbol:
- In the URL —
url="https://192.168.88.2@vrf1/…"(works for HTTP/HTTPS, not for SFTP). - In the
addressproperty —address=192.168.88.2@vrf1 - As a separate
addressparameter —address=@vrf1combined with a URL that supplies the IP.
The address property can be combined with VRF and separated with "@" (address=192.168.88.2@vrf1) or simply as address parameter with "@" symbol before the VRF name, as shown below (uses the address from the URL and combines it with the VRF name from the address parameter):
[admin@MikroTik] /> /tool/fetch url="sftp://192.168.88.2" address=@test src-path=test.txt user=admin password="" upload=yes
status: finished
Sending information to a remote host
It is possible to use an HTTP POST request to send information to a remote server that is prepared to accept it. In the following example, geographic coordinates are sent to a PHP page:
/tool/fetch http-method=post http-header-field="Content-Type:application/json" http-data="{\"lat\":\"56.12\",\"lon\":\"25.12\"}" url="https://testserver.lv/index.php"
In this example, the data is uploaded as a file. Since variable data comes from a file, a file can only be up to 4 KB in size. This is a limitation of RouterOS variables.
/export file=.rsc
:global data [/file/get [/file/find name=.rsc] contents];
:global url "https://prod-51.westeurope.logic.azure.com:443/workflows/blabla/triggers/manual/paths/invoke....";
/tool/fetch mode=https http-method=put http-data=$data url=$url
Return value to a variable
It is possible to save the result of the fetch command to a variable.
Example 1
You can trigger a certain action based on the result that an HTTP page returns. The following example disables ether2 whenever a PHP page returns "0":
{
:local result [/tool/fetch url=https://10.0.0.1/disable_ether2.php as-value output=];
:if ($result->"status" = "finished") do={
:if ($result->"data" = "0") do={
/interface/ethernet/set ether2 disabled=yes;
} else={
/interface/ethernet/set ether2 disabled=no;
}
}
}
Example 2
When fetch fails, it is possible to access the error code ("code") and returned HTTP headers ("http-headers"):
:onerror err,attr in={ /tool/fetch http://127.0.0.1/error as-value} do={:put $err;:put ($attr->"code");:put ($attr->"http-headers")}
failure: Status 404, Not Found
404
Cache-Control: no-store;Connection: Keep-Alive;Content-Length: 99;Content-Type: text/html;Date: Tue, 09 Dec 2025 13:27:44 GMT;Expires: 0;Pragma: no-cache;X-Frame-Options: sameorigin