?
Solved

How do i read a txt file from a webserver

Posted on 2003-03-18
5
Medium Priority
?
142 Views
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
0
Comment
Question by:samuel_prasanna
[X]
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
5 Comments
 

Accepted Solution

by:
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.
0
 
LVL 3

Assisted Solution

by:emadat
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;
var
     hSession, hURL: HInternet;
     Buffer: array[1..BufferSize] of Byte;
     BufferLen: DWORD;
     mStrm: TMemoryStream;
begin
     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;
               try
                    repeat
                         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);
               finally
                    mStrm.Free;
               end;
          finally
               InternetCloseHandle(hURL);
          end
     finally
          InternetCloseHandle(hSession);
     end;
end;
//=======================================================

Emad
0
 

Expert Comment

by:CleanupPing
ID: 9316681
samuel_prasanna:
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 
EXPERTS:
Post your closing recommendations!  No comment means you don't care.
0

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