I have provided the base-point code above. You can always tailor it to suit your needs. For example, try logging the errors in your console to get a better idea on what the error is instead of the generic message that I’m currently showing.
I simply logged console.log(fileList.length) after await fetchFileList(). But you can also check that in the Netlify API documentation response (file_count) property.
This will only download all the files that exist in your publish folder. The deploy logs indicate which folder is being published (like publishing files from dist). If your file exists in that folder, it will be available for download.