Community discussions

 
User avatar
martini
Member Candidate
Member Candidate
Topic Author
Posts: 296
Joined: Tue Dec 21, 2004 12:13 am

Cant read file large then 4085 bytes

Wed Apr 28, 2010 11:28 am

Try to use this script
:global content [/file get [/file find name=test.txt] contents] ;
:global contentLen [ :len $content ] ;

:global lineEnd 0;
:global line "";
:global lastEnd 0;


:do {
       :set lineEnd [:find $content "\r\n" $lastEnd ] ;
       :set line [:pick $content $lastEnd $lineEnd] ;
       :set lastEnd ( $lineEnd + 2 ) ;

       :local tmpArray [:toarray $line] ;
	:if ( [:pick $tmpArray 0] != "" ) do={
	:put $tmpArray;
         /ppp secret add name=[:pick $tmpArray 0] password=[:pick $tmpArray 1] \
             local-address=[:pick $tmpArray 2] remote-address=[:pick $tmpArray 3] \
             profile=[:pick $tmpArray 4] service=[:pick $tmpArray 5];
}
} while ($lineEnd < $contentLen)
But if file large then 4085 bytes nothing happens
Can somebody help with this ??
 
User avatar
mrz
MikroTik Support
MikroTik Support
Posts: 5942
Joined: Wed Feb 07, 2007 12:45 pm
Location: Latvia
Contact:

Re: Cant read file large then 4085 bytes

Wed Apr 28, 2010 11:38 am

This is current limitation, and there is no workaround
Next time use search:
http://forum.mikrotik.com/viewtopic.php ... it#p202842
 
dssmiktik
Forum Veteran
Forum Veteran
Posts: 732
Joined: Fri Aug 17, 2007 8:42 am

Re: Cant read file large then 4085 bytes

Wed Apr 28, 2010 11:45 am

If the file contents can not be read (due to file size limitation), an empty string is returned.

You could try adding this if file contents cannot be retrieved:
:global content [/file get [/file find name=test.txt] contents] ;
:global contentLen [ :len $content ] ;

+ :if ([:len $contentLen] = 0) do={
+    :error ("Could not retrieve test.txt contents")
+ }


:global lineEnd 0;
:global line "";
:global lastEnd 0;


:do {
       :set lineEnd [:find $content "\r\n" $lastEnd ] ;
       :set line [:pick $content $lastEnd $lineEnd] ;
       :set lastEnd ( $lineEnd + 2 ) ;

       :local tmpArray [:toarray $line] ;
   :if ( [:pick $tmpArray 0] != "" ) do={
   :put $tmpArray;
         /ppp secret add name=[:pick $tmpArray 0] password=[:pick $tmpArray 1] \
             local-address=[:pick $tmpArray 2] remote-address=[:pick $tmpArray 3] \
             profile=[:pick $tmpArray 4] service=[:pick $tmpArray 5];
}
} while ($lineEnd < $contentLen)
Doug
 
User avatar
dynek
Member Candidate
Member Candidate
Posts: 193
Joined: Tue Jan 21, 2014 10:03 pm

Re: Cant read file large then 4085 bytes

Fri Apr 15, 2016 3:11 pm

6 years later, 4kb is still the max size of files that can be read from a Mikrotik's script?
This sounds like April's Fool and makes me go back to what computers used to be 30 years ago.
 
jarda
Forum Guru
Forum Guru
Posts: 7604
Joined: Mon Oct 22, 2012 4:46 pm

Fri Apr 15, 2016 4:19 pm

Even 30 years ago there was not such low limit as I remember.
 
dssmiktik
Forum Veteran
Forum Veteran
Posts: 732
Joined: Fri Aug 17, 2007 8:42 am

Re: Cant read file large then 4085 bytes

Sat Apr 16, 2016 6:47 am

I believe it may have something to do with the buffering mechanism being used to fetch / stream data. At one point, I thought this limitation applied to comments as well, but I think that is no longer the case.

Regardless, it would be nice to at least see some streaming API, even if we an only buffer 4kb chunks, we could eventually read / write the entire contents of a file.
Doug
 
midenok
newbie
Posts: 39
Joined: Fri Dec 27, 2013 5:34 pm

Re: Cant read file large then 4085 bytes

Mon Apr 25, 2016 7:40 pm

Hey, this means I can't parse files??? No other ways to read by chunks? I want to parse http://txt.proxyspy.net/proxy.txt
RouterOS 6.34
 
dssmiktik
Forum Veteran
Forum Veteran
Posts: 732
Joined: Fri Aug 17, 2007 8:42 am

Re: Cant read file large then 4085 bytes

Tue Apr 26, 2016 5:54 am

Hey, this means I can't parse files??? No other ways to read by chunks? I want to parse http://txt.proxyspy.net/proxy.txt
Unfortunately not if the contents is > 4kb.
You could setup an external service to transform the data into a RouterOS string via local variable. This would allow you to consume the entire file, provided enough memory. If the file already exists on the router, you could use fetch to ship the file to the external service, and retrieve streaming data that way. This is not ideal, but well,it works.
Doug
 
midenok
newbie
Posts: 39
Joined: Fri Dec 27, 2013 5:34 pm

Re: Cant read file large then 4085 bytes

Tue Apr 26, 2016 8:37 am

Hey, this means I can't parse files??? No other ways to read by chunks? I want to parse http://txt.proxyspy.net/proxy.txt
Unfortunately not if the contents is > 4kb.
You could setup an external service to transform the data into a RouterOS string via local variable. This would allow you to consume the entire file, provided enough memory. If the file already exists on the router, you could use fetch to ship the file to the external service, and retrieve streaming data that way. This is not ideal, but well,it works.
Nah, much simpler is to run perl under metarouter. But I'm amazed how primitive and lame routerscript is. It literally can't do something a little bit more complex than 2+2. And if it by some star confluence can, then it will be big pain and shaman dances...
RouterOS 6.34
 
User avatar
macsrwe
Long time Member
Long time Member
Posts: 655
Joined: Mon Apr 02, 2007 5:43 am
Location: Arizona, USA
Contact:

Re: Cant read file large then 4085 bytes

Fri May 13, 2016 10:10 am

:-x !!!

I just wasted five hours tonight writing a script to be periodically run on every one of our routers (including CPEs) to update common configuration scripts if newer versions of those scripts were available on a server.

Because FTP fetch doesn't preserve the date-modified of the source file, it had to depend on being able to determine if the contents of file A were or were not equal to the contents of file B. I tested this out before spending time writing the script, but the files I tried it out on were smaller files and so they worked correctly. I finished the entire script before I discovered that ROS always told me that the files were equal whether or not it was true. That's five hours wasted that I could have used to make progress on something else. And I'm stuck with the conclusion that there is absolutely no other way to do what it is I needed to do.

Who is online

Users browsing this forum: No registered users and 11 guests