conditionaly remove files

i’ve following line in my script for transferring files to remote

/tool fetch address=192.168.200.254 src-path=$filename user=mt mode=ftp password=sr@4944 dst-path=$filename upload=yes;

i need to remove the file from MT only after successful transfer. if ftp can not be done for network trouble or remote server is down , the file will not be removed from MT

thanks

By “MT” I am guessing you mean the router?
So you are uploading a file to a FTP server and only want to delete it if the transfer was successful, right?

An easy way to test if it showed up at the FTP server would be to attempt a download. But that only works if the destination file only exist after a successful transfer.
This should work:

{
  /tool fetch address=192.168.200.254 src-path=$filename user=mt mode=ftp password=sr@4944 dst-path=$filename upload=yes
  :delay 5
  /tool fetch address=192.168.200.254 src-path=$filename user=mt mode=ftp password=sr@4944 dst-path=($filename . ".test") upload=no
  :delay 5
  :if ([print count-only where name=($filename . ".test")] > 0) do={
    /file remove ($filename . ".test")
    /file remove $filename
  }
}

(You may be able to remove the “:delay 5” calls, but they are nice to have in case something is a little slow on the FTP server.)

Another, and maybe prettier way to do it, would be to use the API to delete the file from the router when the FTP server has successful received the file.
This can be done with something like this:

/file/print
=.proplist=.id
?name=<filename>

<save the .id you receive in the reply>

/file/remove
=.id=<.id>

Of course that depends on what you are doing with the file once you receive it and if you are able to contact the router via the API at all.

thanks dean,

urs one is the perfect solution i guess. though i found following script is working properly

/tool fetch address=192.168.200.254 src-path=$filename user=mt mode=ftp password=sr@4944 dst-path=$filename upload=yes;
:log info “$filename File Sent”;
/file remove [find name=$filename];
:log info “$filename removedt”;

if file is not sent the next remove command is not working . so file wont be removed. but i’ll work with ur script.

dean, can u plz check my another post http://forum.mikrotik.com/t/need-to-save-simple-queue-output-to-a-file/95203/1


regards

If the script fails and stops executing when the FTP upload fails, then what was the issue to begin with?
But yeah, my script was the only way I could think of to check if the FTP server has the file.