Can you please help how to read file content (.backup and .rsc) from local mikrotik storage to be uploaded using $data to https remote server?
I do not see how can you use chunks for upload / http PUT method.
Can you please reference documentation stating that $data is limited do 63 KB in RouterOS 7 ?
@msatter I am also interested and did not find a documented way for reading the file into variable, on RouterOS 7 when file is bigger then 10 KB but smaller then 60 KB.
The key detail is what on the other end accepts. I’ll presume your referring to curl that supports a “-F” for forms and supports a “@” to include a file. This depends on HTML5’s <… input=file> within some , and enctype can be “multipart/form-data” or “x-www-urlencoded” ( curl defaults to one, depending on version and content-type). So those are TWO types of file upload, and other ways too.
But unlike curl,
/tool/fetch
does nothing to help with the data= part. AFAIK there is not a script I’ve seen that build the needed MIME nor encodes a /file. And, if it’s binary file, even a script may not be able to access the contents of the file to send nor encode it without more scripting. For text files, it might be possible to build the needed data= for a file upload, but not easy.
Basically RouterOS doesn’t have any primitives to build or parse any of the HTTP content-types. It will happily send a content-type and whatever data you build into a script “str” type. But ain’t going to help with the data at all today. Currently, you can’t even encode or decode JSON to RouterOS array, which is even bigger limitation IMO. This is why you need scripts for JSON, or rextended’s “chunk download”, to workaround to the lack of support dealing with the HTTP data.
Maybe someone else know of a workaround to form data and encoding… but you may want to look at other ways of transfer files than “HTTP upload”. You could turn this around and have the REST API or SFTP on the webserver and pull the file based on an HTTP request.
Doing SFTP or other things is not possible due to other reasons in my case. I am aware of this options.
Please, lets focus here on how to anyhow send any file from mikrotik to remote HTTP server. (not vice versa, etc.)
The other end is HTTP web server, working with standard HTTP stuff. I do have control on that side and I can program whatever is needed. For now I have setup HTTP REST APi endpoint accepting anything / anyhow, just to get somehow the file from mikrotik.
Regarding content type, it can be setup manually via /tool fetch as I can see, but I can also fix that on server side.
I do not need manipulation with JSON on routeros side anyhow.
So, what exactly is RouterOS limitation for /tool fetch working with http post for sending file? I think is just documentation lacking but, could be worse / not implemented features, which exactly ones?
Since they have a backlog of bugs and other features, you may be waiting a while. Essentially /tool/fetch only lets you send a string (but the string can be what ever you want). RouterOS doesn’t have any helpers to encode a form submission (of which a file is a type).
And, RouterOS script can only read files of 4K or less into a string, so this prevent more cleaver solution in scripting. Basically, this would be need to work, as a first step of many, to be able to send any data from a file:
:global filedata [/file get myfile contents]
:put $filedata
Look I ain’t arguing you ROS shouldn’t support some “file upload”. All I was saying “file upload” can happen in a variety of ways (form-data, WebDAV, etc.) – so it’s not as simple as a missing “files=” min fetch.
What you’re asking “There has to be some workaround!”… Here the problem, as you note, is variable sizes are limited, so you can’t encode anything beyond 4K in ROS script. So yes you might have more workarounds possible if variables WERE bigger than >4K. But this one is likely tied to ROS variable aren’t much different than environment variable and the Linux kernel has some limit to size of them. Since scripts have to run the same on a CHR as a mAP, the limit can’t be TOO high since it break scripts on low memory devices. And limitless variables are attach surfaces for buffer overflows.
Containers (e.g. Docker) will likely be here first, so you’d be able to spin up an container to run whatever curl or other method is needed.
Should /tool/fetch has more of of curl “encoding” options? You’d have my vote.
I understand your point about option to send file is not always the same.
In my case, i test with some test.txt about 1 KB, and is not working, received data does not contain data from file anyhow
*) fetch - added “head” option for “http-method”;
*) fetch - added “patch” option for “http-method”;
*) fetch - allow specifying link-local address in FTP mode;
*) fetch - allow to use certificate and check-certificate parameters only in HTTPS mode;
*) fetch - do not require “content-length” for HTTP (introduced in v7.13);
*) fetch - fixed DNS resolving when domain has only AAAA entries (introduced in v7.13);
*) fetch - fixed fetch execution when unexpected data is received in HTTP payload;
*) fetch - fixed fetch when using “src-path” with HTTP/HTTPS modes (introduced in v7.13);
*) fetch - fixed fetch when using “src-path” with SFTP mode (introduced in v7.13);
*) fetch - fixed incorrect “src-path” error message when “upload=yes”;
*) fetch - fixed IPv4 address logging (introduced in v7.13);
*) fetch - improved fetch stability in SFTP mode;
*) fetch - improved file download stability with HTTP/HTTPS modes;
*) fetch - less verbose logging;
*) fetch - print all “Set-Cookies” headers in response;
*) fetch - treat any 2xx HTTP return code as success (introduced in v7.13);