Problem with FTP upload via script

Good day.
I have several mikrotik routers which i administer remotely.
It is: CCR1016-12G(tile), RB1100AHx2(powerpc), hEX lite(mipsbe), RB2011UiAS-2HnD(mipsbe), CCR1036-12G-4S(tile), CCR1036-8G-2S+(tile).
I try to use script to backup config file on remote ftp server.

log info "Starting Automatic Backup Script"
:local ftpusername "admin"
:local ftpuserpassword "admin"
:local ftphostname "192.168.1.1"

log info "Get Date"
:global thisdate [/system clock get date]
:global thistime [/system clock get time]
:global datetimestring ([:pick $thisdate 7 11]."-".[:pick $thisdate 0 3]."-".[:pick $thisdate 4 6]."-".$thistime)

log info "Set names"
:local fname ([/system identity get name]."-".$datetimestring.".backup")

log info "$fname"

log info "Starting Backup"
# backup the data
/system backup save name="$fname"
:log info message="System backup finished.";

:log info "Please wait…!!!"
:delay 5s
:log info "Sending Backup Mikrotik to FTP Server…………."
/tool fetch address="$ftphostname" src-path="$fname" user="$ftpusername" password="$ftpuserpassword" port=21 upload=yes mode=ftp dst-path="mikrotik_backup/$fname"

:log info "Remove Files"
:delay 1
/file remove "$fname"
:log info "Finished Backup Script…!!!!"

All works fine on the router with mipsbe architecture.
There is a problem on the others routers. When script trying to upload file to ftp server - it wont upload the file or start it and then goes to error. Script going fail.

[admin@192.168.1.25] > /tool fetch address=“192.168.1.1” src-path=“192.168.1.25-2017-apr-25-13:29:00.backup” user=“admin” password=“admin” port=21 upload=yes mode=ftp dst-path=“mikrotik_backup/192.168.1.25-2017-apr-25-13:29:00.backup”
status: failed

failure: connection timeout
[admin@192.168.1.25] >

Have you tried increasing the delay between the backup and ftp? If the CPU is under load it might take longer than 5s to complete and show up in directory.

Yes, I tried to do it. Result is the same.

Does it work if run ftp upload command from terminal?
I have backups scripts run on CCRs and RBs and they all work ok.
Except situation then NAS is in standby mode - in this case my script fails in first retry (stops with timeout error) but succeed on second/third (then NAS woke up).
Also check ftp log on server side - may be some hint is there…

It doesn’t work from terminal too. Log-file on the FTP server is OK.
Can you give me example of the your script. I will try it on my routers.

My script is little bit more complicate %) :
I split creating backups, sending them and clearing in three different scripts.
Backups created each week and their filenames put in to the queue.
Router try send them via FTP each 15 minutes (if I remember right).
Once per week old backups deleted and only last three left.
FTP:

Script named func_ftp:

#########################################################
# Wrapper for /tools fetch mode=ftp
#  Input:
#    upload=yes/no
#    user
#    password
#    address
#    host
#    src-path
#    dst-path
#    ascii=yes/no
#    url
#    resfile

:local ftpres "ftpresult.txt"
:if ([:len $resfile]>0) do={:set ftpres $resfile}

:local cmd "/tool fetch mode=ftp"
:if ([:len $upload]>0) do={:set cmd "$cmd upload=$upload"}
:if ([:len $user]>0) do={:set cmd "$cmd user=\"$user\""}
:if ([:len $password]>0) do={:set cmd "$cmd password=\"$password\""}
:if ([:len $address]>0) do={:set cmd "$cmd address=\"$address\""}
:if ([:len $host]>0) do={:set cmd "$cmd hos=\"$hos\""}
:if ([:len $"src-path"]>0) do={:set cmd "$cmd src-path=\"$"src-path"\""}
:if ([:len $"dst-path"]>0) do={:set cmd "$cmd dst-path=\"$"dst-path"\""}
:if ([:len $ascii]>0) do={:set cmd "$cmd ascii=\"$ascii\""}
:if ([:len $url]>0) do={:set cmd "$cmd url=\"$url\""}

#:put ">> $cmd"

:global FTPRESULT
:set FTPRESULT "none"

:local script "\
 :global FTPRESULT;\
 :do {\
   $cmd;\
   :set FTPRESULT \"success\";\
 } on-error={\
  :set FTPRESULT \"failed\";\
 }\
"
:execute script=$script file=$ftpres
:local cnt 0
#:put "$cnt -> $FTPRESULT"
:while ($cnt<100 and $FTPRESULT="none") do={ 
 :delay 1s
 :set $cnt ($cnt+1)
 #:put "$cnt -> $FTPRESULT"
}
:local content [/file get [find name=$ftpres] content]
if ($content~"finished") do={:return "success"}
:return $FTPRESULT

To call it:

#FTP server 
############################
:local ftphost 192.168.x.x
:local ftpport 21
:local ftpuser "mkbackup"
:local ftppassword "xxxxxxxxxxx"
:local ftppath "backups/CCR-Home"
:local ftpfile "123.backup"
:local ftp [:parse [/system script get func_ftp source]]

:local res [$ftp upload=yes user=$ftpuser password=$ftppassword src-path=$ftpfile address=$ftphost dst-path=($ftppath."/".$ftpfile) resfile="log.ftp.txt"]
:put "Result=$res"
:return $res

Difference with usual fetch that script run in different thread and log file with result is created/checked i.e. I can get status - success or fail.
If you wish I can put here full source of my backup system - it is easy to install and config.

It will be great, if you can do it)