...
Fetch is one of the console tools in Mikrotik MikroTik RouterOS. It is used to copy files to/from a network device via HTTP, HTTPS, FTP or SFTP (Support for SFTP added on v6.45), it . 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; In HTTPS mode by default, no certificate checks are made, but setting check-certificate to yes enables trust chain validation from the local certificate store (can be used only in HTTPS mode).
Properties
Property | Description |
---|---|
address (string; Default: ) | IP address of the device to copy file from. |
as-value (set | not-set; Default: not-set) | Store the output in a variable, should be used with the output property. |
ascii (yes | no; Default: no) | Can be used with FTP and TFTP |
certificate (string; Default: ) | Certificate that should be used for host verification. Can be used only in HTTPS mode. |
check-certificate (yes | yes-without-crl | no; Default: no) | Enables trust chain validation from local certificate store. yes-without-crl, validates |
a certificate, not performing CRL check (certificate revocation list). Can be used only in HTTPS mode. | |
dst-path (string; Default: ) | Destination filename and path. |
duration (time; Default: ) | Time how long fetch should run. |
host (string; Default: ) | A domain name or virtual domain name (if used on a website, from which you want to copy information). For example, address=wiki.mikrotik.com host=forum.mikrotik.com In this example the resolved ip address is the same (66.228.113.27), but hosts are different. |
http-auth-scheme (basic|digest; Default: basic) | HTTP authentication scheme |
http-method ( |
delete|get|head|post|put|patch; Default: get) |
HTTP method to use |
http-data (string; Default: ) |
The data, that is going to be sent, when using PUT or POST methods. Data limit is 64Kb. |
http-header-field (string; Default: *empty*) |
List of all header fields and their values, in the form of http-header-field=h1:fff,h2:yyy | |
http-content-encoding (deflate|gzip; Default: *empty*) | Encodes the payload using gzip or deflate compression and adds a corresponding Content-Encoding header. Usable for HTTP POST and PUT only. |
keep-result (yes | no; Default: yes) | If yes, creates an input file. |
mode (ftp|http|https|sftp|tftp; Default: http) | Choose the protocol of connection - http, https , ftp, sftp or tftp. |
output (none|file|user|user-with-headers; Default: file) | Sets where to store the downloaded data.
|
password (string; Default: anonymous) | Password, which is needed for authentication to the remote device. |
port (integer; Default: ) | Connection port. |
src-address (ip address; Default: ) | Source address that is used to establish connection. Can be used only HTTP/S and SFTP modes. |
src-path (string; Default: ) | Title of the remote file you need to copy. |
upload (yes | no; Default: no) | Only (S)FTP modes support |
upload. If enabled then fetch will be used to upload files to a remote server. |
Requires src-path and dst-path parameters to be set. | |
url (string; Default: ) | URL pointing to file. Can be used instead of address and src-path parameters. |
user (string; Default: anonymous) |
Username, which is needed for authentication to the remote device. |
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.
...
Code Block | ||
---|---|---|
| ||
{ :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:
Code Block | ||
---|---|---|
| ||
[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]
|