Complex dst-path in script

I’ve got a problem with dst-path argument in my script. I need to upload file to the specific directory on my server, and it’s not working as it supposed to. Here is source:

:log info "export beginning now"

:global exportfile ([/system identity get name] . "-" . [:pick [/system clock get date] 7 11] . [:pick [/system clock get date] 0 3] . [:pick [/system clock get date] 4 6] . "-" . [/system resource get board-name])

/export compact file=$exportfile

:log info "export pausing for 10s"

:delay 10s

:log info "export being transfered"

/tool fetch address=10.0.0.2 port=21 user=ftp password=ftppass mode=ftp upload=yes src-path="$exportfile" dst-path="upload/$exportfile"

:log info "export pausing for 10s"

:delay 10s

:log info "remove export"

/file rem $exportfile

:delay 5s

:log info "export finished"

Here is output of console after running it:

/system script run Export-ftp 
  status: failed

failure: cannot open file

Problem doesn’t apear if i do it directly without script as this:

/tool fetch address=10.0.0.2 port=21 user=ftp password=ftppass mode=ftp upload=yes src-path=router.rsc dst-path=upload/router.rsc

Feel free the help me solve this issue;)

Try changing the following lines to see what’s going on at this stage:

From this:

:log info “export being transfered”

/tool fetch address=10.0.0.2 port=21 user=ftp password=ftppass mode=ftp upload=yes src-path=“$exportfile” dst-path=“upload/$exportfile”

:log info “export pausing for 10s”

To this:

:log info “export being transfered”
:log info “Export file name: $exportfile”

/tool fetch address=10.0.0.2 port=21 user=ftp password=ftppass mode=ftp upload=yes src-path=“$exportfile” dst-path=“upload/$exportfile”

:log info “export pausing for 10s”

This should confirm that the value being passed as $exportfile is the same as you’re expecting, for starters.

Everything is ok with file name. There is a problem with complex path as argument of ‘dst-path=’. It seems that i cannot pass complex path via variable. If i use it from CLI without variables it works, but when i put variable to this option it returns:

  status: failed

failure: cannot open file

which is connected with write permissions on ftp server. RoS tries to write the file in main directory, while it should write it one level deeper.
I’ve already tried pass whole path as one variable, as combined string, and just a second ago without variable, just with complex path and it also didn’t work. As for me the clue is in '' sign in that path, but for now i don’t know what to do with it.

I get the same result. I don’t think it’s the dst-path, I think it is a file handle issue.

Putting the export in one script and the ftp in another and then calling them separately from a third script works.

Can u paste your sample here? I will check your solution soon, but now i don’t see what’s the difference of dividing one script into two others invoked by third one.

Well, I’ve checked it once again and i’ve found what was wrong. The only problem was with (yes, yes i know;) ) file name. Variable $exportfile was right, but this was the file name without extension ‘.rsc’. Correct file was created on ftp server but without .rsc extension, that’s how i’ve figured it out, and due to that it had 0 bytes size. So the proper line of the script should look like this:

/tool fetch address=10.0.0.2 port=21 user=ftp password=ftppass mode=ftp upload=yes src-path=("$exportfile" . ".rsc") dst-path=("upload/$exportfile" . ".rsc")

No it works perfectly, it’s time for bash scripts managing backup files on ftp servers;)

Yes, it is working. When I tested last night, I didn’t use the global, but did a find for the file in the second script.

I then used the file index to get the file name, which included the “.rsc”.

Late nights…