How do i read a txt file from a webserver

Posted on 2003-03-18
Medium Priority
Last Modified: 2010-04-04
hi everyone,
i would like to save some data in the website in a txt file and i would like to read the file using delphi and display it in the client window

for eg: if the
Host Name : ftp.tripod.com
User Name : xxxxxx
Password  : xxxxxx
And the file name is myfirst.txt

i want to open the file and read the data in it plz help me........... Sam
Question by:samuel_prasanna
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions

Accepted Solution

Paivlek earned 80 total points
ID: 8165113
There are a set of internet components available through www.overbyte.be

One is an FTP client that will log in and download the file for you, or if you can access it from the web like www.tripod.com/user/myfirst.txt, you can do that with the http component and would be faster as it wouldn't need to log in etc.

Assisted Solution

emadat earned 80 total points
ID: 8166917
Here is a function that you call with the full url of your text file e.g:

PageText := GetHTMLPage(http://www.your_site.com/textfile.txt);

You should include WinInet in your uses clause for the function to work.
function GetHTMLPage(strURL: String): String;
const BufferSize = 1024;
     hSession, hURL: HInternet;
     Buffer: array[1..BufferSize] of Byte;
     BufferLen: DWORD;
     mStrm: TMemoryStream;
     Result := '';
     hSession := InternetOpen(PChar('MyApplication'), INTERNET_OPEN_TYPE_PRECONFIG, nil, nil, 0);
     if hSession<>nil then try
          hURL := InternetOpenURL(hSession, PChar(strURL), nil, 0, 0, 0);
          if hURL<>nil then try
               mStrm := TMemoryStream.Create;
                         InternetReadFile(hURL, @Buffer, SizeOf(Buffer), BufferLen);
                         if BufferLen>0 then mStrm.WriteBuffer(Buffer, BufferLen);
                    until BufferLen = 0;
                    SetLength(Result, mStrm.Size);
                    CopyMemory(@Result[1], mStrm.memory, mStrm.Size);


Expert Comment

ID: 9316681
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
Post your closing recommendations!  No comment means you don't care.

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question