# The maximum size of a read/written file.

**URL:** <https://forum.mikrotik.com/t/the-maximum-size-of-a-read-written-file/167507>\
**Category:** Scripting\
**Created:** [June 19, 2023, 3:15pm UTC](https://forum.mikrotik.com/t/the-maximum-size-of-a-read-written-file/167507 "2023-06-19T15:15:33Z")\
**Posts on this page:** 20\
**Page:** 2

<div class="post-metadata">

**Author:** ![optio](https://forum.mikrotik.com/letter_avatar/optio/32/6_449c533f586939b6e5f246632a46421f.png) [@optio](https://forum.mikrotik.com/u/optio)\
**Post date:** [June 21, 2023, 4:31pm UTC](https://forum.mikrotik.com/t/the-maximum-size-of-a-read-written-file/167507/21 "2023-06-21T16:31:32Z")

</div>

> [@](#):
>
> Well, changing the 4K file limit from content= be a start… @DyadyaGenya and @rextended have come a long way here… to run into yet another limitation & another set of complex scripting to workaround.

Personally I will go with approach: In loop where records are appended to variable for file save, before append record to that variable I will first check size of that variable and if that length of that variable + length of record variable exceeds 4K then I will write current content value into file segment, then assign current record variable into that variable. File segment counter needs to be raised each time when file is saved. At the end you will have files like: _sms.txt.1, sms.txt.2, sms.txt.3…_ which can be merged on other system where are downloaded.

---

<div class="post-metadata">

**Author:** ![optio](https://forum.mikrotik.com/letter_avatar/optio/32/6_449c533f586939b6e5f246632a46421f.png) [@optio](https://forum.mikrotik.com/u/optio)\
**Post date:** [June 21, 2023, 4:32pm UTC](https://forum.mikrotik.com/t/the-maximum-size-of-a-read-written-file/167507/22 "2023-06-21T16:32:48Z")

</div>

…

---

<div class="post-metadata">

**Author:** ![DyadyaGenya](https://forum.mikrotik.com/letter_avatar/dyadyagenya/32/6_449c533f586939b6e5f246632a46421f.png) [@DyadyaGenya](https://forum.mikrotik.com/u/DyadyaGenya)\
**Post date:** [June 21, 2023, 6:12pm UTC](https://forum.mikrotik.com/t/the-maximum-size-of-a-read-written-file/167507/23 "2023-06-21T18:12:18Z")

</div>

> [@](#):
>
> Personally I will go with approach: In loop where records are appended to variable for file save, before append record to that variable I will first check size of that variable and if that length of that variable + length of record variable exceeds 4K then I will write current content value into file segment, then assign current record variable into that variable. File segment counter needs to be raised each time when file is saved. At the end you will have files like: _sms.txt.1, sms.txt.2, sms.txt.3…_ which can be merged on other system where are downloaded.

Why consider the volume of a variable, if everything is well written to a file without it. Have you seen my example above? There is exactly the same principle as you described, only without checking the volume of the variable.  
I do not argue, the example is not very well designed, but it was one of the first scripts that I wrote and I published it here just so that the @rextended understood what I was talking about.

---

<div class="post-metadata">

**Author:** ![optio](https://forum.mikrotik.com/letter_avatar/optio/32/6_449c533f586939b6e5f246632a46421f.png) [@optio](https://forum.mikrotik.com/u/optio)\
**Post date:** [June 21, 2023, 6:28pm UTC](https://forum.mikrotik.com/t/the-maximum-size-of-a-read-written-file/167507/24 "2023-06-21T18:28:48Z")

</div>

> [@](#):
>
> Why consider the volume of a variable, if everything is well written to a file without it. Have you seen my example above? There is exactly the same principle as you described, only without checking the volume of the variable.

Well that is not exactly, that part is crucial if you don’t want to reach 4k limit. Topic is The maximum size of a read/written file. which is actually limit of variable that contains content of a file.

> [@](#):
>
> I do not argue, the example is not very well designed, but it was one of the first scripts that I wrote and I published it here just so that the @rextended understood what I was talking about.

I saw your script example, yes it contains loop for writing file segments, but it is lacking logic which I mentioned.

---

<div class="post-metadata">

**Author:** ![msatter](https://forum.mikrotik.com/letter_avatar/msatter/32/6_449c533f586939b6e5f246632a46421f.png) [@msatter](https://forum.mikrotik.com/u/msatter)\
**Post date:** [June 21, 2023, 6:36pm UTC](https://forum.mikrotik.com/t/the-maximum-size-of-a-read-written-file/167507/25 "2023-06-21T18:36:40Z")

</div>

> [@](#):
>
> > [@](#):
> >
> > This was the startingpoint: [http://forum.mikrotik.com/t/send-script-output-to-a-file/116250/14](http://forum.mikrotik.com/t/send-script-output-to-a-file/116250/14)
> 
> I think that it is more correct to continue in this topic, and not in the one where the link is.
> 
> I tried doing something like this:
> 
> ```plaintext
> :local sms [/system script get "sms.txt" source]; 
> :put $sms
> 
> ```
> 
> But it gives an error: “no such item”

```plaintext
execute "/system script get \"sms.txt\" source" file="sms.txt"

```

I don’t do scripting anymore but this should write to the file. If you come up with the correct commands it should write to the file sms.txt

---

<div class="post-metadata">

**Author:** ![optio](https://forum.mikrotik.com/letter_avatar/optio/32/6_449c533f586939b6e5f246632a46421f.png) [@optio](https://forum.mikrotik.com/u/optio)\
**Post date:** [June 21, 2023, 7:25pm UTC](https://forum.mikrotik.com/t/the-maximum-size-of-a-read-written-file/167507/26 "2023-06-21T19:25:53Z")

</div>

@DyadyaGenya try with this

```plaintext
:local output ( [/interface lte at-chat lte1 wait=yes input="AT+CMGL=4" as-value]->"output" )
:local lenOutput [:len $output]
:local splitSize 4095
:local offset 0
:local part 1

:while ($offset < $lenOutput) do={
  :local nameFile ("sms".$part.".txt")

  :if (($offset + $splitSize) > $lenOutput) do={
    /file add name=$nameFile contents=[:pick $output $offset $lenOutput]
    :set offset $lenOutput
  } else={
    /file add name=$nameFile contents=[:pick $output $offset ($offset + $splitSize)]
    :set offset ($offset + $splitSize)
  }

  :set part ($part + 1)
}

```

---

<div class="post-metadata">

**Author:** ![msatter](https://forum.mikrotik.com/letter_avatar/msatter/32/6_449c533f586939b6e5f246632a46421f.png) [@msatter](https://forum.mikrotik.com/u/msatter)\
**Post date:** [June 21, 2023, 9:42pm UTC](https://forum.mikrotik.com/t/the-maximum-size-of-a-read-written-file/167507/27 "2023-06-21T21:42:49Z")

</div>

@optio Why still self limit to 4096 bytes!? Many people here walked into this limitation for many years and some found little gems in RouterOS which works around problems. One of those is “:execute”

Lets keep it simple, this will store the output of a command or script to a file like it was display in you screen.

```plaintext
:execute "/ip/route/export" file="test"

```

It adds the default extension “txt” to the filename, here is that “test”

You can find more about :execute: [https://wiki.mikrotik.com/wiki/Manual:Scripting#Global\_commands](https://wiki.mikrotik.com/wiki/Manual:Scripting#Global_commands)

---

<div class="post-metadata">

**Author:** ![optio](https://forum.mikrotik.com/letter_avatar/optio/32/6_449c533f586939b6e5f246632a46421f.png) [@optio](https://forum.mikrotik.com/u/optio)\
**Post date:** [June 21, 2023, 10:17pm UTC](https://forum.mikrotik.com/t/the-maximum-size-of-a-read-written-file/167507/28 "2023-06-21T22:17:33Z")

</div>

> [@](#):
>
> @optio Why still self limit to 4096 bytes!? Many people here walked into this limitation for many years and some found little gems in RouterOS which works around problems. One of those is “:execute”
> 
> Lets keep it simple, this will store the output of a command or script to a file like it was display in you screen.
> 
> ```plaintext
> :execute "/ip/route/export" file="test"
> 
> ```
> 
> It adds the default extension “txt” to the filename, here is that “test”
> 
> You can find more about :execute: [https://wiki.mikrotik.com/wiki/Manual:Scripting#Global\_commands](https://wiki.mikrotik.com/wiki/Manual:Scripting#Global_commands)

Ok, from DyadyaGenya script example correct answer will be then

```plaintext
:execute ":put ([/interface lte at-chat lte1 wait=yes input=\"AT+CMGL=4\" as-value]->\"output\")" file=sms.txt

```

---

<div class="post-metadata">

**Author:** ![optio](https://forum.mikrotik.com/letter_avatar/optio/32/6_449c533f586939b6e5f246632a46421f.png) [@optio](https://forum.mikrotik.com/u/optio)\
**Post date:** [June 21, 2023, 10:54pm UTC](https://forum.mikrotik.com/t/the-maximum-size-of-a-read-written-file/167507/29 "2023-06-21T22:54:12Z")

</div>

> [@](#):
>
> But what is your native language?

This may answer [https://forummikrotik.ru/viewtopic.php?p=89403#p89403](https://forummikrotik.ru/viewtopic.php?p=89403#p89403) 🙂

---

<div class="post-metadata">

**Author:** ![Amm0](https://forum.mikrotik.com/user_avatar/forum.mikrotik.com/amm0/32/1630_2.png) [@Amm0](https://forum.mikrotik.com/u/Amm0)\
**Post date:** [June 22, 2023, 1:56am UTC](https://forum.mikrotik.com/t/the-maximum-size-of-a-read-written-file/167507/30 "2023-06-22T01:56:21Z")

</div>

> [@](#):
>
> > [@](#):
> >
> > But what is your native language?
> 
> This may answer [https://forummikrotik.ru/viewtopic.php?p=89403#p89403](https://forummikrotik.ru/viewtopic.php?p=89403#p89403) 🙂

LOL. About the same...

> Всё написано выше. Имеющий глаза - увидит

(Google tells me, that means "Everything is written above. Those who have eyes will see.")

---

<div class="post-metadata">

**Author:** ![rextended](https://forum.mikrotik.com/user_avatar/forum.mikrotik.com/rextended/32/67729_2.png) [@rextended](https://forum.mikrotik.com/u/rextended)\
**Post date:** [June 22, 2023, 7:34am UTC](https://forum.mikrotik.com/t/the-maximum-size-of-a-read-written-file/167507/31 "2023-06-22T07:34:03Z")

</div>

> [@](#):
>
> > [@](#):
> >
> > But what is your native language?
> 
> This may answer [https://forummikrotik.ru/viewtopic.php?p=89403#p89403](https://forummikrotik.ru/viewtopic.php?p=89403#p89403) 🙂

What does it have to do with it, I wanted him to specify it, if he wanted...  
If you look closely you'll see that the Uncle Женя lives in Chernihiv, and was born on January 17.. 😆 (Женя жарт... 😉 )  
I don't put the year, if he wants he can put it there... 😆

---

<div class="post-metadata">

**Author:** ![msatter](https://forum.mikrotik.com/letter_avatar/msatter/32/6_449c533f586939b6e5f246632a46421f.png) [@msatter](https://forum.mikrotik.com/u/msatter)\
**Post date:** [June 22, 2023, 11:12am UTC](https://forum.mikrotik.com/t/the-maximum-size-of-a-read-written-file/167507/32 "2023-06-22T11:12:09Z")

</div>

> [@](#):
>
> > [@](#):
> >
> > @optio Why still self limit to 4096 bytes!? Many people here walked into this limitation for many years and some found little gems in RouterOS which works around problems. One of those is “:execute”
> > 
> > Lets keep it simple, this will store the output of a command or script to a file like it was display in you screen.
> > 
> > ```plaintext
> > :execute "/ip/route/export" file="test"
> > 
> > ```
> > 
> > It adds the default extension “txt” to the filename, here is that “test”
> > 
> > You can find more about :execute: [https://wiki.mikrotik.com/wiki/Manual:Scripting#Global\_commands](https://wiki.mikrotik.com/wiki/Manual:Scripting#Global_commands)
> 
> Ok, from DyadyaGenya script example correct answer will be then
> 
> ```plaintext
> :execute ":put ([/interface lte at-chat lte1 wait=yes input=\"AT+CMGL=4\" as-value]->\"output\")" file=sms.txt
> 
> ```

No, I wrote "It adds the default extension “txt” to the filename, here is that “test” ".

```plaintext
:execute ":put ([/interface lte at-chat lte1 wait=yes input=\"AT+CMGL=4\" as-value]->\"output\")" file="sms"

```

---

<div class="post-metadata">

**Author:** ![optio](https://forum.mikrotik.com/letter_avatar/optio/32/6_449c533f586939b6e5f246632a46421f.png) [@optio](https://forum.mikrotik.com/u/optio)\
**Post date:** [June 22, 2023, 12:48pm UTC](https://forum.mikrotik.com/t/the-maximum-size-of-a-read-written-file/167507/33 "2023-06-22T12:48:59Z")

</div>

> [@](#):
>
> ```plaintext
> :execute ":put ([/interface lte at-chat lte1 wait=yes input=\"AT+CMGL=4\" as-value]->\"output\")" file="sms"
> 
> ```

Works also with .txt extension in file param, then it will not append .txt to filename.

---

<div class="post-metadata">

**Author:** ![DyadyaGenya](https://forum.mikrotik.com/letter_avatar/dyadyagenya/32/6_449c533f586939b6e5f246632a46421f.png) [@DyadyaGenya](https://forum.mikrotik.com/u/DyadyaGenya)\
**Post date:** [June 22, 2023, 12:58pm UTC](https://forum.mikrotik.com/t/the-maximum-size-of-a-read-written-file/167507/34 "2023-06-22T12:58:49Z")

</div>

> [@](#):
>
> No, I wrote "It adds the default extension “txt” to the filename, here is that “test” ".
> 
> ```plaintext
> :execute ":put ([/interface lte at-chat lte1 wait=yes input=\"AT+CMGL=4\" as-value]->\"output\")" file="sms"
> 
> ```

In fact, both options work. And if you tell me how to read the received files, then this will be an almost ideal solution. I write “almost” because for some reason (maybe it’s something wrong with me) after rebooting the router, the file disappears. It has to be copied to another location or renamed.

---

<div class="post-metadata">

**Author:** ![pe1chl](https://forum.mikrotik.com/user_avatar/forum.mikrotik.com/pe1chl/32/55588_2.png) [@pe1chl](https://forum.mikrotik.com/u/pe1chl)\
**Post date:** [June 22, 2023, 1:18pm UTC](https://forum.mikrotik.com/t/the-maximum-size-of-a-read-written-file/167507/35 "2023-06-22T13:18:35Z")

</div>

That depends on the type of router. Unfortunately, MikroTik has missed the chance of defining standard paths of persistent/volatile files.  
Now, you will have to check yourself and use a path suitable for your router type and configuration.

---

<div class="post-metadata">

**Author:** ![msatter](https://forum.mikrotik.com/letter_avatar/msatter/32/6_449c533f586939b6e5f246632a46421f.png) [@msatter](https://forum.mikrotik.com/u/msatter)\
**Post date:** [June 22, 2023, 1:37pm UTC](https://forum.mikrotik.com/t/the-maximum-size-of-a-read-written-file/167507/36 "2023-06-22T13:37:05Z")

</div>

> [@](#):
>
> > [@](#):
> >
> > ```plaintext
> > :execute ":put ([/interface lte at-chat lte1 wait=yes input=\"AT+CMGL=4\" as-value]->\"output\")" file="sms"
> > 
> > ```
> 
> Works also with .txt extension in file param, then it will not append .txt to filename.

Not overhere on ROS 7.10

---

<div class="post-metadata">

**Author:** ![optio](https://forum.mikrotik.com/letter_avatar/optio/32/6_449c533f586939b6e5f246632a46421f.png) [@optio](https://forum.mikrotik.com/u/optio)\
**Post date:** [June 22, 2023, 1:43pm UTC](https://forum.mikrotik.com/t/the-maximum-size-of-a-read-written-file/167507/37 "2023-06-22T13:43:16Z")

</div>

> [@](#):
>
> Not overhere on ROS 7.10

I’m also on 7.10

```plaintext
> /system/routerboard/print 
  routerboard: yes
  model: D53G-5HacD2HnD
  serial-number: XXXXXXXX
  firmware-type: ipq4000L
  factory-firmware: 7.1beta5
  current-firmware: 7.10
  upgrade-firmware: 7.10
> :execute ":put ([/interface lte at-chat lte1 wait=yes input=\"AT+CMGL=4\" as-value]->\"output\")" file="sms.txt"

```

![sms_file.png](https://data-discourse.cdn.mikrotik.com/original/3X/6/c/6c96c38baec527aa569d8b0726f48dd783855a47.png)

---

<div class="post-metadata">

**Author:** ![msatter](https://forum.mikrotik.com/letter_avatar/msatter/32/6_449c533f586939b6e5f246632a46421f.png) [@msatter](https://forum.mikrotik.com/u/msatter)\
**Post date:** [June 22, 2023, 1:50pm UTC](https://forum.mikrotik.com/t/the-maximum-size-of-a-read-written-file/167507/38 "2023-06-22T13:50:43Z")

</div>

If you want to restore the stored data or transfer to a differen router then selective path exporting and exporting is the simple way.

I don’t know how thatworks with LTE or SMS because I don’t have that.

In this posting is mentioned that extension does not need to be RSC.

[http://forum.mikrotik.com/t/the-maximum-size-of-a-read-written-file/167507/36](http://forum.mikrotik.com/t/the-maximum-size-of-a-read-written-file/167507/36)

---

<div class="post-metadata">

**Author:** ![rextended](https://forum.mikrotik.com/user_avatar/forum.mikrotik.com/rextended/32/67729_2.png) [@rextended](https://forum.mikrotik.com/u/rextended)\
**Post date:** [June 22, 2023, 1:57pm UTC](https://forum.mikrotik.com/t/the-maximum-size-of-a-read-written-file/167507/39 "2023-06-22T13:57:04Z")

</div>

\*\*\* see my next post \*\*\*

---

<div class="post-metadata">

**Author:** ![optio](https://forum.mikrotik.com/letter_avatar/optio/32/6_449c533f586939b6e5f246632a46421f.png) [@optio](https://forum.mikrotik.com/u/optio)\
**Post date:** [June 22, 2023, 2:00pm UTC](https://forum.mikrotik.com/t/the-maximum-size-of-a-read-written-file/167507/40 "2023-06-22T14:00:09Z")

</div>

> [@](#):
>
> In fact, both options work. And if you tell me how to read the received files, then this will be an almost ideal solution.

Already explained above [http://forum.mikrotik.com/t/the-maximum-size-of-a-read-written-file/167507/1](http://forum.mikrotik.com/t/the-maximum-size-of-a-read-written-file/167507/1) and system note can be used as workaround. You can also provide file over http and use chunked download with fetch tool, also you have post with script by rextended [http://forum.mikrotik.com/t/how-to-download-only-one-piece-of-file-at-a-time-with-tool-fetch-and-put-it-inside-a-variable/151020/1](http://forum.mikrotik.com/t/how-to-download-only-one-piece-of-file-at-a-time-with-tool-fetch-and-put-it-inside-a-variable/151020/1)

> [@](#):
>
> I write “almost” because for some reason (maybe it’s something wrong with me) after rebooting the router, the file disappears. It has to be copied to another location or renamed.

you can use flash of usb storage for persistence, depends on device, to save it on flash use

```plaintext
file="flash/sms"

```

[Previous page](https://forum.mikrotik.com/t/the-maximum-size-of-a-read-written-file/167507.md?page=1)

[Next page](https://forum.mikrotik.com/t/the-maximum-size-of-a-read-written-file/167507.md?page=3)
