how to get text from a file on a server
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
-
- Posts: 361
- Joined: Wed Apr 27, 2011 2:12 pm
how to get text from a file on a server
I have tried 10 ways to sunday using the file: command, the url command, the ftp:// command, etc.
I am simply trying to read a number from a text file located on a web server without having to download it at all.
How is this done?
I am sure it is easy, but for some odd reason I just cannot get the coding right.
Thank you.
Mike
I am simply trying to read a number from a text file located on a web server without having to download it at all.
How is this done?
I am sure it is easy, but for some odd reason I just cannot get the coding right.
Thank you.
Mike
-
- VIP Livecode Opensource Backer
- Posts: 9785
- Joined: Wed May 06, 2009 2:28 pm
- Location: New York, NY
Re: how to get text from a file on a server
Hi.
Generically, something like this does not work:
Are you sure you know the pathName to the file? If not, you can use the "open file" command to get that information directly.
Craig
Generically, something like this does not work:
Code: Select all
open file yourFile for read
read from file yourFile until EOF
close file yourFile
Craig
-
- VIP Livecode Opensource Backer
- Posts: 9867
- Joined: Sat Apr 08, 2006 7:05 am
- Location: Los Angeles
- Contact:
Re: how to get text from a file on a server
Being on a web server limits your options, since HTTP is designed to deliver whole resources and provides no built-in means to extract specific portions of a resource.
If this is your own server, you could consider having your client call an LC Server script which reads the desired portion of the file and returns only that.
If it's not a server you manage your options will be more limited, and you may even need to just download the whole thing - how large is it?
If this is your own server, you could consider having your client call an LC Server script which reads the desired portion of the file and returns only that.
If it's not a server you manage your options will be more limited, and you may even need to just download the whole thing - how large is it?
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
-
- Posts: 361
- Joined: Wed Apr 27, 2011 2:12 pm
Re: how to get text from a file on a server
File is tiny. 1k to 2k.
Right now it’s on a server I control but in the future I will not have explicit access. No way to read it?
It’s just a simple text file.
Mike
Right now it’s on a server I control but in the future I will not have explicit access. No way to read it?
It’s just a simple text file.
Mike
-
- Posts: 361
- Joined: Wed Apr 27, 2011 2:12 pm
Re: how to get text from a file on a server
No. Something like that does not work.dunbarx wrote: ↑Wed Jul 22, 2020 7:21 pmHi.
Generically, something like this does not work:Are you sure you know the pathName to the file? If not, you can use the "open file" command to get that information directly.Code: Select all
open file yourFile for read read from file yourFile until EOF close file yourFile
Craig
Currently, I download the file and then read it but I’d rather read it in place and not touch it.
I do use tsnet with sftp to read and write to it. But I was hoping to read it in place and store the 1st line in a variable.
Mike
-
- VIP Livecode Opensource Backer
- Posts: 9867
- Joined: Sat Apr 08, 2006 7:05 am
- Location: Los Angeles
- Contact:
Re: how to get text from a file on a server
1k-2k? Unless there's something wrong with the connection, or some unusual constraint in the problem (e.g. real-time gaming*) where the difference between 2k and a few bytes makes a noticeable difference, just download it. The overall throughput difference probably isn't much.
My own rule of thumb is that if it's smaller than a file system's block size (usually 4k these days), I don't spend wetware cycles thinking about it for local or remote IO.
* I was recently tickled to learn that many modern game devs have been using UDP for real-time updates to avoid the overhead of TCP, where apparently interpolating between missed packets is less impactful than the cost of TCP's assured delivery for certain types of game play:
https://www.gafferongames.com/post/udp_vs_tcp/
My own rule of thumb is that if it's smaller than a file system's block size (usually 4k these days), I don't spend wetware cycles thinking about it for local or remote IO.
* I was recently tickled to learn that many modern game devs have been using UDP for real-time updates to avoid the overhead of TCP, where apparently interpolating between missed packets is less impactful than the cost of TCP's assured delivery for certain types of game play:
https://www.gafferongames.com/post/udp_vs_tcp/
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
-
- VIP Livecode Opensource Backer
- Posts: 9867
- Joined: Sat Apr 08, 2006 7:05 am
- Location: Los Angeles
- Contact:
Re: how to get text from a file on a server
Thinking about this more, you could modify libURL to cut off the HTTP read after a few bytes. But that's a lot of work, with minimal payoff unless the problem you're solving has specialized needs.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
-
- Posts: 361
- Joined: Wed Apr 27, 2011 2:12 pm
Re: how to get text from a file on a server
Richard,
I agree with you. In fact, I already do this. However, I am having a very WEIRD problem.
I cannot discuss it fully, but in a nutshell, I keep track of what is being written and track it at all times.
Say I have a number, say 50. Now I add one to it and write it. Now it's, ta dah, 51.
Right? Not right. The next time I d/l the file, it's either blank or 1.
WTF.
I have no idea how to track this, i'll call it, bug. It's making my system very difficult to deal with as a result of not being reliable.
I use a lot of encryption and I am wondering if the time it takes to encrypt large files is somehow superceeding writing this tiny little file
and zeroing it out? I'm just not sure.
Therefore, i'd like a way to just read the number from a distance from a source that is not yet corrupted.
Instead of downloading it, I just want to read the number and store it in a new variable so that if the file becomes corrupted, I can write it back to it.
That's the best I can explain it due to being patents pending.
Mike
I agree with you. In fact, I already do this. However, I am having a very WEIRD problem.
I cannot discuss it fully, but in a nutshell, I keep track of what is being written and track it at all times.
Say I have a number, say 50. Now I add one to it and write it. Now it's, ta dah, 51.
Right? Not right. The next time I d/l the file, it's either blank or 1.
WTF.
I have no idea how to track this, i'll call it, bug. It's making my system very difficult to deal with as a result of not being reliable.
I use a lot of encryption and I am wondering if the time it takes to encrypt large files is somehow superceeding writing this tiny little file
and zeroing it out? I'm just not sure.
Therefore, i'd like a way to just read the number from a distance from a source that is not yet corrupted.
Instead of downloading it, I just want to read the number and store it in a new variable so that if the file becomes corrupted, I can write it back to it.
That's the best I can explain it due to being patents pending.
Mike
-
- VIP Livecode Opensource Backer
- Posts: 9867
- Joined: Sat Apr 08, 2006 7:05 am
- Location: Los Angeles
- Contact:
Re: how to get text from a file on a server
I like weird problems. If you want to discuss it via email, feel free to send an NDA. I can't guarantee I can fix it but sometimes having a second pair of eyes on something can help.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
-
- Posts: 361
- Joined: Wed Apr 27, 2011 2:12 pm
Re: how to get text from a file on a server
I made a work around today.
I am writing to a .ini file at the very beginning and then checking against it at any write time.
It works as error correction but is more like a bandage and not a fix.
Mike
I am writing to a .ini file at the very beginning and then checking against it at any write time.
It works as error correction but is more like a bandage and not a fix.
Mike
-
- VIP Livecode Opensource Backer
- Posts: 9785
- Joined: Wed May 06, 2009 2:28 pm
- Location: New York, NY
Re: how to get text from a file on a server
I did not see that a server was the source.
So, er, never mind...
Craig
So, er, never mind...
Craig
-
- VIP Livecode Opensource Backer
- Posts: 7266
- Joined: Sat Apr 08, 2006 8:31 pm
- Location: Minneapolis MN
- Contact:
Re: how to get text from a file on a server
I need to update data on the server a lot, and I send the updated info to a server script which writes it to the correct file. Same for retrieval, the script reads the file and returns the info I need. This gets around permissions errors and has been reliable.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com
HyperActive Software | http://www.hyperactivesw.com
Re: how to get text from a file on a server
If that's actually what you want to do have you tried this?I am simply trying to read a number from a text file located on a web server without having to download it at all.
How is this done?
...
It’s just a simple text file.
Code: Select all
put url "https://mysite.com/mysimplenumberfile.txt" into theNumberIWanted
-
- VIP Livecode Opensource Backer
- Posts: 9867
- Joined: Sat Apr 08, 2006 7:05 am
- Location: Los Angeles
- Contact:
Re: how to get text from a file on a server
What needs to be in place to allow writes to the server? How is authentication handled so those writes can't be made by others?jiml wrote: ↑Thu Jul 23, 2020 5:53 pmIf that's actually what you want to do have you tried this?I am simply trying to read a number from a text file located on a web server without having to download it at all.
How is this done?
...
It’s just a simple text file.
Code: Select all
put url "https://mysite.com/mysimplenumberfile.txt" into theNumberIWanted
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
-
- Posts: 361
- Joined: Wed Apr 27, 2011 2:12 pm
Re: how to get text from a file on a server
Not writing to the server in this case, just wanting to read a text file's contents.
I have reading and writing through SFTP using TSNet working perfectly by downloading/transferring the file and reading it on the node.
I was hoping to avoid all that extra code and just 'take it's temperature' essentially.
I made a work around that works.
Thanks everyone.
Mike
I have reading and writing through SFTP using TSNet working perfectly by downloading/transferring the file and reading it on the node.
I was hoping to avoid all that extra code and just 'take it's temperature' essentially.
I made a work around that works.
Thanks everyone.
Mike