Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

How do i read a txt file from a webserver

Posted on 2003-03-18
5
Medium Priority
?
143 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
3 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Suggested Courses

580 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