Page tree

Summary

Fetch is one of the console tools in Mikrotik RouterOS. It is used to copy files to/from a network device via HTTP, FTP or SFTP (Support for SFTP added on v6.45), it can also be used to send POST/GET requests and send any kind of data to a remote server. The HTTPS protocol is supported; by default, no certificate checks are made, but setting check-certificate to yes enables trust chain validation from the local certificate store.

Configuration Examples

The following example shows how to copy the file with filename "conf.rsc" from a device with ip address 192.168.88.2 by FTP protocol and save it as file with filename "123.rsc". User and password are needed to login into 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 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 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                jun/01/2010 11:59:51

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, we send geographic coordinates to a PHP page:

/tool fetch http-method=post http-content-type="application/json" http-data="{\"lat\":\"56.12\",\"lon\":\"25.12\"}" url="https://testserver.lv/index.php"   

Of course, you can use Fetch with scripts and fill the above command with variables from the RouterOS GPS menu.

Return value to a variable

Since RouterOS v6.43 it is possible to save the result of the fetch command to a variable. For example, it is possible to trigger a certain action based on the result that an HTTP page returns. You can find a very simple example below that disables ether2 whenever a PHP page returns "0":

{
    :local result [/tool fetch url=https://10.0.0.1/disable_ether2.php as-value output=user];
    :if ($result->"status" = "finished") do={
        :if ($result->"data" = "0") do={
            /interface ethernet set ether2 disabled=yes;
        } else={
            /interface ethernet set ether2 disabled=no;
        }
    }
}

SFTP

Since 6.45beta50 /tool fetch support SFTP (SSH File Transfer Protocol) protocol:

[admin@MikroTik] > /tool fetch url="sftp://10.155.126.200/home/x86/Desktop/50MB.zip" user=x86 password=root dst-path=disk1
      status: downloading
  downloaded: 1048KiB
       total: 51200KiB
    duration: 6s
-- [Q quit|D dump|C-z pause]


  • No labels