I slow my version because I want also manage fetch errors
(thanks for msatter for the idea of identify inside the type of list)
(I never see a msatter thanks to me for the method for download a file only one piece at time)
http://forum.mikrotik.com/t/fetch-capable-of-following-redirects/151723/7
This is a work in progress code for manage the fetch errors, is ready to paste on terminal for testing purpose.
/file remove [find where name="testfetch.txt"]
{
:local jobid [:execute file=testfetch.txt script="/tool fetch url=http://mikrotik.com"]
:put "Waiting the end of process for file testfetch.txt to be ready, max 20 seconds..."
:global Gltesec 0
:while (([:len [/sys script job find where .id=$jobid]] = 1) && ($Gltesec < 20)) do={
:set Gltesec ($Gltesec + 1)
:delay 1s
:put "waiting... $Gltesec"
}
:put "Done. Elapsed Seconds: $Gltesec\r\n"
:if ([:len [/file find where name="testfetch.txt"]] = 1) do={
:local filecontent [/file get [/file find where name="testfetch.txt"] contents]
:put "Result of Fetch:\r\n****************************\r\n$filecontent\r\n****************************"
} else={
:put "File not created."
}
}
on this case we obtain at the end “closing connection: <302 Found “https://mikrotik.com/”> 159.148.147.196:80 (4)”
because “http ://mikrotik.com” redirect to “https ://mikrotik.com/” (and redirect again to “https ://www.mikrotik.com/”) (added spaces on purpose)