Community discussions

MikroTik App
 
luca1234567
newbie
Topic Author
Posts: 31
Joined: Tue May 15, 2018 1:27 am
Contact:

Create directory on remote FTP server

Fri Dec 11, 2020 11:41 pm

I use RouterOS v6.46.8(logn-term).

I write I script to backup locally graph data and then backup it to external FTP server.
I NEED to create automaticaly directory because the name of directory is derived from actual time and date, I WANT to execute a backup of graphs data downloaded from local device.

I use I code like the follow.
# Backup graph data to $LocalSavePath
 ...

# Backup to FTP
# Dir all file in sub-directory $LocalSavePath
:foreach i in=[/file find name~("^".$LocalSavePath) ] do={
  :if ([:len [:find [/file get $i type] "file"]]>0) do={
    :local FileName [/file get $i name]

    :local FTPServerSavePath ($FTPServerSavePathRoot.$DateTimeCode."/".[:pick $FileName [:len $LocalSavePath] [:len $FileName]]
    :set Status 7
    :do {
#      :put ("Testpoint : FTP Status=".$Status)
      :do {
        /tool fetch address=$FTPServerAddres port=$FTPServerPort mode=ftp user=$FTPServerUsername password=$FTPServerPassword upload=yes src-path=$FileName dst-path=$FTPServerSavePath
        :set Status -1
       } on-error={
        :set Status ($Status-1)
        :put ("Testpoint : FTP Status=".$Status)
        :delay 10
       }
     } while ($Status>0);
    :if ($Status<0) do={
      :put ("Testpoint : FTP OK")
     } else {
      :put ("Testpoint : FTP Error")
     }

   }
 }
Where for example:
$LocalSavePath = "uSD/Report/"
$FileName = "uSD/Report/graph/cpu/daily.gif"
$FTPServerSavePathRoot = "Router_Report/"
$DateTimeCode = "20201130-1023" (Deriverd from Time & Data at backup moment)
The result is:
FTPServerSavePath = "Router_Report/20201130-1023/graph/cpu/daily.gif"

The folder "20201130-1023" do NOT EXIST, and I CANNOT create it manualy, because the name was created on the fly.
And the fecth now respond failed to copy the file.

If I log-in to the FTP server from a Windows Client with the SAME username and password used in script I can creare folders.
Then the script can make the upload, so NOT is a problem of config, so NOT is a problem of device settings and permissions.

As described in my forum post viewtopic.php?f=9&t=169738
So as fecth create local destination folder if not exists when DOWNLOAD. It CAN create directory path if not exist when UPLOAD a file to a remote server.
Because there in NOT another method in Mikrotik language script to create folder.


I ask to Mikrotik if they can implement this simple thinks.
If similar requests will be from users, then we will check on how to implement such a feature Create a directory on the remote FTP server, in the future.

How many people think this is a good think ?
 
excession
Frequent Visitor
Frequent Visitor
Posts: 95
Joined: Mon May 11, 2015 8:16 pm

Re: Create directory on remote FTP server

Mon Jun 06, 2022 4:30 pm

+1 !
 
User avatar
Jotne
Forum Guru
Forum Guru
Posts: 3279
Joined: Sat Dec 24, 2016 11:17 am
Location: Magrathean

Re: Create directory on remote FTP server

Sun Jul 24, 2022 10:15 am

Or you can use an FTP server that automatically make the directory if its missing and the user has create directory permission.
 
luca1234567
newbie
Topic Author
Posts: 31
Joined: Tue May 15, 2018 1:27 am
Contact:

Re: Create directory on remote FTP server

Thu Aug 04, 2022 12:37 am

Or you can use an FTP server that automatically make the directory if its missing and the user has create directory permission.
1) FTP client, not server.
2) Why use another device to do something that the Mikrotik Router can DO ?
3) If the name of directory was created in the Mikrotik script, by date and time, how can know the other device with FTP Client that name?
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11967
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: Create directory on remote FTP server

Thu Aug 04, 2022 3:10 am

But why you deplete time without take the easy path?

Set the name of the file directly like
"20201130-1023-graph-cpu-daily.gif"
and you solve.
You have "indexed" images based on date and time,
and you do not have thousand of images called daily.gif.....

Who is online

Users browsing this forum: No registered users and 15 guests