473,785 Members | 2,299 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Open and read from http://someserver/file.txt

Is there a simple way of opening a text file from a server, and reading from
it line by line?

IE

http://someserver/file.txt contains a couple of hundred lines. Each line is
the name of a file. I want to read this list of files into an array of
strings. I don't have any control over the creation of file.txt so I really
need to be able to read from it in it's existing format, a list of files
seperated by carriage returns.

Thanks,

Nik Coughlin
Jul 20 '05 #1
7 7647
If the text file is on the same server as the JavaScript this might
be possible, else it would probably run into some security issues.
You could attempt to make a hidden IFRAME, load the text file, and read
it by accessing its document.body.i nnerText or something...

<IFRAME SRC="file.txt" ID="myframe" onLoad="readFil e();"
STYLE="visibili ty:hidden;width :0px;height:0px ">
</IFRAME>

function readFile() {
thedoc = document.myfram e.contentWindow .document.body. innerText;
splitted = thedoc.split('\ n');
}

I haven't tested it, but it should be more or less like this. If the
file is on another server, you might need to run it as a signed script
or you'll need some server-side solution.

Good luck,
Vincent

Nik Coughin wrote:
Is there a simple way of opening a text file from a server, and reading from
it line by line?

IE

http://someserver/file.txt contains a couple of hundred lines. Each line is
the name of a file. I want to read this list of files into an array of
strings. I don't have any control over the creation of file.txt so I really
need to be able to read from it in it's existing format, a list of files
seperated by carriage returns.

Thanks,

Nik Coughlin


Jul 20 '05 #2
Vincent van Beveren wrote:
If the text file is on the same server as the JavaScript this might
be possible, else it would probably run into some security issues.
I don't really understand how it could be an issue. Text file available to
anyone with a browser, how can it be a security issue that my JavaScript can
see it too?

I'm not saying you're wrong, from what I've seen it seems that you're right.
I just *can't* for the life of me see the security issue with JavaScript
being able to access a file that is on the WWW.
You could attempt to make a hidden IFRAME, load the text file, and
read it by accessing its document.body.i nnerText or something...

<IFRAME SRC="file.txt" ID="myframe" onLoad="readFil e();"
STYLE="visibili ty:hidden;width :0px;height:0px ">
</IFRAME>

function readFile() {
thedoc = document.myfram e.contentWindow .document.body. innerText;
splitted = thedoc.split('\ n');
}

I haven't tested it, but it should be more or less like this. If the
file is on another server, you might need to run it as a signed script
or you'll need some server-side solution.

Good luck,
Vincent


Thanks, I'll give it a go. Otherwise I guess it'll have to be server-side.
Jul 23 '05 #3
On Fri, 2 Apr 2004 09:18:26 +1200, Nik Coughin <nr***********@ woosh.co.nz>
wrote:
Vincent van Beveren wrote:
If the text file is on the same server as the JavaScript this might
be possible, else it would probably run into some security issues.


I don't really understand how it could be an issue. Text file available
to anyone with a browser, how can it be a security issue that my
JavaScript can see it too?

I'm not saying you're wrong, from what I've seen it seems that you're
right.
I just *can't* for the life of me see the security issue with JavaScript
being able to access a file that is on the WWW.


Security is privacy oriented. Possibilities.. .

Accessing HTML pages from other domains:

A script could interfere with a page. An extreme case might be one that
periodicly checks other pages for form fields that contain personal
information, whether it be credit card information, passwords, or e-mail
addresses. It's not likely that it would happen, but browser developers
would be negligent if they allowed to be possible simply on the basis that
it's "not likely".
Accessing the local file system:

Well, reasons here should be obvious.
Accessing remote file systems:

This probably isn't a security issue, just that client-side JavaScript is
just that: client-side. There are very few reasons why a client-side
script should need to access something on the server. That's what
server-side languages are for.

There might be better examples, but this is what first entered my head.

Mike

--
Michael Winter
M.******@blueyo nder.co.invalid (replace ".invalid" with ".uk" to reply)
Jul 23 '05 #4
Michael Winter wrote:
Security is privacy oriented. Possibilities.. .

Accessing HTML pages from other domains:

A script could interfere with a page. An extreme case might be one
that periodicly checks other pages for form fields that contain
personal information, whether it be credit card information,
passwords, or e-mail addresses. It's not likely that it would happen,
but browser developers would be negligent if they allowed to be
possible simply on the basis that it's "not likely".
Is that even possible? HTML pages don't store the content of form fields.
The browser does, and then sends that information to the server. There's no
way that allowing JS to have read access to a file on another domain --
which anyone with an Internet connection can access anyhow -- would allow
the fields of a form to be read.

Accessing the local file system:

Well, reasons here should be obvious.

Completely :)
There might be better examples, but this is what first entered my
head.


Thanks for taking the time to write Mike :) I guess what I'm trying to say
is, if a file is on the Internet and can be read by anyone with a browser,
then why can't my JavaScript read it?
Jul 23 '05 #5
On Fri, 2 Apr 2004 10:01:56 +1200, Nik Coughin <nr***********@ woosh.co.nz>
wrote:
Michael Winter wrote:
[stealing data from another page]
Is that even possible? HTML pages don't store the content of form
fields. The browser does, and then sends that information to the
server. There's no way that allowing JS to have read access to a file
on another domain -- which anyone with an Internet connection can access
anyhow -- would allow the fields of a form to be read.
I was referring to an active page, in a frame, say. :)

A gateway site might load other pages into a frame, knowing full well that
a user might enter sensitive data into them. It could read it and send it
to a server for storage. The "Same Origin Policy" prevents that.

[snip]
I guess what I'm trying to say is, if a file is on the Internet and can
be read by anyone with a browser, then why can't my JavaScript read it?


As I said, client-side JavaScript is for performing actions on the client.
Very few browsers provide ways for scripts to communicate with remote
machines - server-side scripts should have provided them with all the
information they need.

I did forget to point out that there is an FAQ entry on this:

<URL:http://jibbering.com/faq/#FAQ4_38>

It does provide a solution that would work under some circumstances, but
if you were dependent on this approach, your page might be utterly useless
for unsupporting browsers.

Mike

--
Michael Winter
M.******@blueyo nder.co.invalid (replace ".invalid" with ".uk" to reply)
Jul 23 '05 #6
Michael Winter wrote:
On Fri, 2 Apr 2004 10:01:56 +1200, Nik Coughin
<nr***********@ woosh.co.nz> wrote:
Michael Winter wrote: I was referring to an active page, in a frame, say. :)

A gateway site might load other pages into a frame, knowing full well
that a user might enter sensitive data into them. It could read it
and send it to a server for storage. The "Same Origin Policy"
prevents that.


Ahhh... gotcha :)
[snip]
I guess what I'm trying to say is, if a file is on the Internet and
can be read by anyone with a browser, then why can't my JavaScript
read it?


As I said, client-side JavaScript is for performing actions on the
client. Very few browsers provide ways for scripts to communicate
with remote machines - server-side scripts should have provided them
with all the information they need.

I did forget to point out that there is an FAQ entry on this:

<URL:http://jibbering.com/faq/#FAQ4_38>

It does provide a solution that would work under some circumstances,
but if you were dependent on this approach, your page might be
utterly useless for unsupporting browsers.

Mike


It's OK, I was just looking for a lazy way out to do something very simple
that is probably better done with PHP.

Thanks again!
Jul 23 '05 #7
On Fri, 2 Apr 2004 10:01:56 +1200, "Nik Coughin"
<nr***********@ woosh.co.nz> wrote:
Michael Winter wrote:
Security is privacy oriented. Possibilities.. .

Accessing HTML pages from other domains:

A script could interfere with a page. An extreme case might be one
that periodicly checks other pages for form fields that contain
personal information, whether it be credit card information,
passwords, or e-mail addresses.


Most likely reason is to subvert IP based protection, if a certain
page is only accessible within the intranet, I just need to fool
someone to visit the page, then I can proxy myself through them.

Also if I can proxy myself through someone I can pretend to be them on
other sites, maybe sending spam, maybe ...

Jim.
--
comp.lang.javas cript FAQ - http://jibbering.com/faq/

Jul 23 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
3550
by: BadOmen | last post by:
I have a text file that I want to save from my program. But I don't want to save the empty lines. I want to delete everything after the last character, Is that possible? Then when I read the text file i don't want to read empty lines(If the user as edit the file in notpad..), sense it makes commas at all new lines and then split the text at every comma in to an array. The array will contain empty "slot's" if there is a lot of commas in a...
4
6803
by: Otik | last post by:
Hi, I'm trying to open a file with read access only, e.g. FileStream fs = new FileStream("C:\foo.txt", FileMode.Open, FileAccess.Read); The file is open by another process and the FileStream constructor throws an IOException. I thought that it was possible to open a file with read access even if it's being used by another process. Is that not true? Thanks, Otik
9
1977
by: ferbar | last post by:
Hi all, I'm trying to read from the txt file 'ip.packets.2.txt' using the read function. It seems everything ok, but I get a -1 when executing >>bytesr = read(fdo1, bufread, 2); The 'open' function returns the file dsc 3. So this seems ok.. Any idea what might be wrong?
3
34539
by: trellow | last post by:
Hello, I am writing an application that needs to read a file that is already open by another process for writing. When I do the following: FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.Read); BinaryReader br = new BinaryReader(fs); I get the following exception:
1
1235
by: Danny Ni | last post by:
Hi, I have a webform that will pop up window by clicking button or links inside data grid. Here are some sample code snippet: 'For button btnOrder.Attributes.Add("onclick", "window.open('order.aspx?............. 'For datagrid
2
4421
by: OutdoorGuy | last post by:
Greetings, I have a "newbie" question in relation to opening files from C#. I have a Windows form where I allow the user to type in a file extension in a text box (e.g., "xls"). I then take that extension and use that as my filter criteria for the File Open dialog. Once the user selects a file with that extension (from the File Open dialog), I simply want to open that file (whether it is an .xls file, .txt file, etc.). I am...
5
2171
by: Yoshitha | last post by:
Hi I am developing a C#.Net windows application for my project. In that project I have an IDE to work on. The application is similar to Adobe Photoshop. My requirement is as follows. 1) I must be able to save my work in a file with custom file extention (similar to *.PSD in photoshop) 2) After I save my work, if I double click on that file, my work should be opened with my application automatically and I need to be able to work on
5
11223
by: Ryan Liu | last post by:
Hi, Both way works, I'd just ask some experts which way is better? My application creates a log file daily. Now each time when I write a log, I will open the file and append to the end. Ocz, if the file is not exist(e.g. another day), it will creates the file first.
4
3287
by: Claire DURAND | last post by:
Hi, I try to open a distant (not local) XML file in PHP to read an RSS feed. I can open an HTML page and read it with the file() function. But as soon as I try with a RSS feed instead of HTML and I try to read or open with file() or fopen(), it doesn't work, I have the following errors :
0
9489
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10356
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10162
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10100
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9959
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8988
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5396
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5528
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2893
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.