First, You are a autor of the script? If YES then you just use few put/log $variable to describe a problem. Forus is not offitial support channel and any person who help here do it in his free time/resource etc and we have Christmast time :).
In my scenario I not use TheDude at MikroTik and must do checking on new device.
hAP ac2 with pendrive give be a disk1 type=disk, in file print I see path syntax "disk1/directory/file1.txt" .
I use
https://text-compare.com/ to compare both scripts.
Your main/core part is this:
:foreach backupFile in=[/file find] do={
:set backupFileName ($PathPrefix.[/file get ($PathPrefix.$backupFile) name])
:if ([:typeof [:find $backupFileName $sfname]] != "nil") do={
/tool fetch address=$FTPServer port=$FTPPort src-path=($backupFileName) user=$FTPUser mode=ftp password=$FTPPass dst-path="BackupMikrotik/TheDudeServer/$backupFileName" upload=yes
}
}
TIPs:
* My first tip is to every time when you use fetch then use it in separate { } block. For example then you run fetch after fetch after fetch (3x fetch) you notice that can brake transfers, when you use separate block of code then command will be works in step by step instruction and the stdout not breake next command.
* Good way is use do {tool fetch ....} on-error={log error "My error entry for $backupFile <- backupFile variable ."}
* This foreach loop and have a put/log instructions to give you information what a current file are transfer, error's can be better grab that way.
* Tool/Fetch cannot copy a directory type. Remote Path must exist before copy files. Good way is display local directory by:
/file print where name~"disk1/dude" type=directory
disk1/dude
disk1/dude/files
disk1/dude/files/default
disk1/dude/files/default/images
disk1/dude/files/default/mibs
and compare with remote ftp if they exist.
This give us info that your "$PathPrefix.$backupFile" are double the disk1 like "disk1/disk1/dir/file.ext" and is not proper way.
I thinks this place is core problem of not executive script.
And not putting a additional debuging line in script.
Check your loop with my debug's.
{
:local backupFileName ""
:local PathPrefix "disk1/"
:foreach backupFile in=[/file find] do={
put "SIB | backupFile: $backupFile"
put "CheckPoint1"
:set backupFileName ($PathPrefix.[/file get ($PathPrefix.$backupFile) name])
put "CheckPoint2"
do {:put "SIB | backupFileName: $backupFileName"} on-error={put "SIB | backupFileName: ERROR"}
do {:put "SIB | cmd1:"; :put [/file get ($PathPrefix.$backupFile) name]} on-error={put "SIB | cmd1: ERROR"}
#:if ([:typeof [:find $backupFileName $sfname]] != "nil") do={
#/tool fetch address=$FTPServer port=$FTPPort src-path=($backupFileName) user=$FTPUser mode=ftp password=$FTPPass dst-path="BackupMikrotik/TheDudeServer/$backupFileName" upload=yes
#}
}
}
Add/Remove the # at lines.
Copy/Paste with some changes to terminal with clear screen via CTRL+L and Shift+Insert
give you answers where you have errors in script.
Next problem is with your $fname and $sfname and this again have own disk1 suffix again and remote location and local not have got disk1/disk1/disk1/dude/... structure.
Example who copy "disk1/dude/" to remote FTP "BackupMikrotik/TheDudeServer/disk1/dude/..."
{
local backupFileName ""
foreach backupFile in=[/file find where name~"disk1/dude/" type!="directory" size>0 ] do={
#put "File ID: $backupFile"
set $backupFileName [/file get $backupFile name]
put "*** $backupFileName ***"
do {/tool fetch address=$FTPServer mode=ftp port=21 upload=yes user=$FTPUser password=$FTPPass src-path=($backupFileName) dst-path="BackupMikrotik/TheDudeServer/$backupFileName"} on-error={put "FTP ERROR with $backupFileName"}
}
}
I hope with all this information you can re-write your script.
BR Marcin