Community discussions

MikroTik App
 
electravis
Member Candidate
Member Candidate
Topic Author
Posts: 274
Joined: Tue Jan 26, 2010 12:06 am

rename file on ftp upload

Fri Aug 26, 2022 4:51 pm

I am trying to rename a file during the ftp upload process. I want to give it the date and timestamp of the upload time. However I cant seem to figure out the variable or if its even allowed on an ftp upload. The upload works fine if i give the file a static name but not what i am trying to do.

:local date [/system clock get date]
:local time [/system clock get time]
/tool fetch address=xxx.xxx.xxx.xxx src-path=testfile.txt user=xxxxx mode=ftp password=xxxxxx dst-path="[$date][$time].txt" upload=yes;
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11968
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: rename file on ftp upload  [SOLVED]

Fri Aug 26, 2022 6:20 pm

(use search function before open new topic)

This is not a question of knowing or not RouterOS, this is the A-B-C of operating systems.

again same error horror: on time and date are present special characters that do not fit as filename on file system

aug/26/2022 = folder aug / folder 26 / folder 2022....

Use this (and search button is your friend)
{
:global arrMonths {jan="01";feb="02";mar="03";apr="04";may="05";jun="06";jul="07";aug="08";sep="09";oct="10";nov="11";dec="12"}

/system clock
:local ndate  [get date]
:local ntime  [get time]
:local fdname "$[:pick $ndate 7 11]$($arrMonths->[:pick $ndate 0 3])$[:pick $ndate 4 6]$[:pick $ntime 0 2]$[:pick $ntime 3 5]"

/tool fetch mode=ftp upload=yes address=xxx.xxx.xxx.xxx user=xxxxx password=xxxxxx src-path=testfile.txt dst-path="$fdname.txt"
}
 
electravis
Member Candidate
Member Candidate
Topic Author
Posts: 274
Joined: Tue Jan 26, 2010 12:06 am

Re: rename file on ftp upload

Mon Aug 29, 2022 3:30 pm

Thank you

Who is online

Users browsing this forum: UkRainUa and 30 guests