fetch
tool/fetch
Type: Command
Download and upload files and make HTTP requests from the console or scripts. See the Fetch guide.
| Argument | Type | Description |
|---|---|---|
| url | string | Full URL of the resource, for example https://download.mikrotik.com/routeros/7.19/CHANGELOG or ftp://user:password@192.168.88.2/conf.rsc. The scheme selects the mode, and ftp/sftp URLs may carry the credentials. Can replace the separate address and src-path parameters. A VRF cannot be given inside the URL: in https://192.168.88.2@vrf1/ the part after @ is treated as the host name. Use the address parameter for VRF. |
| output | enum (none | file | user | user-with-headers) | Determines where the fetched data is stored.
|
| http-method | enum (get | post | put | delete | head | patch) | HTTP method of the request. PUT and PATCH without
|
| http-auth-scheme | enum (basic | digest) | HTTP authentication scheme for user and password. With basic, the credentials are sent with the first request, without waiting for a challenge. Default: basic. |
| http-data | string | Request body for POST, PUT and PATCH. Maximum data limit is 64 KB. Without a Content-Type in http-header-field, the body is sent as application/x-www-form-urlencoded. |
| http-header-field | multi { array-id, header-field: string } | HTTP header fields and values, in the form of "h1:fff,h2:yyy": a comma starts the next header. To keep a comma inside one header value, escape it with two backslashes, e.g. "h:fff\,yyy" sends h: fff,yyy. Fetch always sends User-Agent: RouterOS <version> and Accept-Encoding: deflate, gzip. |
| check-certificate | enum (no | yes | yes-without-crl) | TLS certificate validation for HTTPS.
|
| certificate | enum | Certificate from the certificate store used for server verification in HTTPS mode. Applicable only when check-certificate is enabled. |
| address | alt { address: address (flags=46vi) , address: ipAddr } | IP address or host name of the target device. Append @vrf_name to run the fetch operation within a specific VRF, or set only address=@vrf_name and let the url parameter supply the address. |
| src-address | alt { ip: ipAddr , ip6: ip6Addr } | Source IP address for establishing the connection. Applicable to HTTP, HTTPS, and SFTP modes only. |
| port | num | Port used for the connection. Default: the port of the mode (80 for http, 443 for https, 21 for ftp, 22 for sftp, 69 for tftp), or the port given in url. |
| mode | enum (http | https | ftp | tftp | sftp) | Protocol used for the connection. With
|
| http-content-encoding | enum (deflate | gzip) | Compresses http-data with gzip or deflate and adds a matching Content-Encoding header. Only applicable to POST and PUT methods. |
| ip-type | enum (any | ipv4 | ipv6) | IP family preference when resolving domain names.
|
| src-path | file | Path of the remote file; with upload=yes, the local file to upload. |
| dst-path | file | Destination path where the fetched file is saved; with upload=yes, the file name on the remote device. Without dst-path, a download is named after the last part of the URL path. |
| user | string | Username for authentication on the remote device. Without user, FTP logs in as anonymous and HTTP sends no credentials. |
| password | string | Password for user. With user and no password, HTTP sends an empty password. |
| host | string | Hostname or virtual hostname of the remote web server. Useful when the same IP serves multiple virtual hosts. For example, address=manual.mikrotik.com host=forum.mikrotik.com. |
| ascii | bool | Enables ASCII mode for FTP/TFTP transfers. Default: no. |
| upload | bool | Enables upload mode for FTP and SFTP transfers: src-path is the local file, and dst-path (or the path in url) the name on the remote device. HTTP uploads are not supported; use http-method=put with http-data. Default: no. |
| sftp-known-hosts-ignore | bool | Skip SSH host key validation for this SFTP transfer. Has an effect when known-hosts-validation in /ip/ssh is enabled; without validation enabled, any host key is accepted. Default: no. |
| keep-result | bool | Deprecated, use the output argument instead. |
| idle-timeout | alt { idle-timeout: time [1 .. 604800] , idle-timeout: enum (none) { none:0 } } | Idle timeout since last read/write action. Default: 10s. |
| http-max-redirect-count | num | Maximum number of HTTP redirects that fetch follows. With the default of 2, a chain of two redirects is followed and a third fails the fetch with the received 3xx status. Default: 2. |
| http-percent-encoding | bool | Percent-encodes every character in the request path except alphanumeric and -._~/?^=:. Default: no. |
| http-version | enum (http1_1 | http2 | http2-forced) | HTTP protocol version. HTTP2 is supported only on ARM64 and x86/CHR devices. Default: http1_1. |
| Read-only Argument | Type | Description |
|---|---|---|
| status | enum (none | connecting | requesting | downloading | uploading | finished | failed) | Current status of the fetch operation. |
| code | num | HTTP status code returned by the server. |
| downloaded | num | Amount downloaded, in KiB, rounded down and at least 1 when data arrived (7 bytes and 2047 bytes both show 1). With output=user, the amount stored in data; compare [:len ($r->"data")] with the limit to detect a cut body. |
| uploaded | num | Amount uploaded, in KiB, rounded down. |
| total | num | Total size of the transfer, in KiB, rounded down. |
| duration | time | The total duration of the fetch operation. |
| data | string | Fetched data when output is user (at most 64512 bytes) or user-with-headers (at most 20480 bytes). A longer body is cut without an error. |
| http-headers | object { http-header: super { key: string , [value] : string } } | HTTP headers returned by the server. |