it seems that the problem is on the fetch command, the console returns information about successful sending and at the moment is pasted next code.
when I enter this code as a script - the exported file is not removed - so the script does not execute to the end.
By the way, why so many delays? Isn’t one delay enough?
My FTP backup script doesn’t even have a delay, I just delete old file right before creating the new one. That way the router also always has its configuration backup saved locally. But maybe that is a security risk?