Right after a boot or a deploy the first request often meets a closed port.
curl --retry 5 --retry-delay 2 --retry-all-errors -fsS -O https://example.com/file.tgz
By default --retry only repeats after transient errors such as a timeout or an HTTP 408, 429, 500, 502, 503, 504, 522 or 524. --retry-all-errors (7.71.0 and newer) retries on any failure, including connection refused. Without --retry-delay the wait starts at one second and doubles up to ten minutes, and --retry-max-time caps the total. Be careful with POST requests, because a retry can send the same data twice. Keep -f as well, so an HTTP error page is not saved as the download.
Further reading: curl manual