uses WinInet, IdHTTP;
procedure InternetZagruzitFajl1(URL, f: string);
const MaxBuffer=65536;
var H1, H2: pointer;
H3: integer;
Buffer: array[1..MaxBuffer] of char;
Count: cardinal;
begin
H1:=InternetOpen('', 0, nil, nil, 0);
try
H2:=InternetOpenURL(H1, PChar(URL), nil, 0, 0, 0);
If H2=nil then
begin
InternetCloseHandle(H1);
Exit;
end;
try
H3:=FileCreate(f);
Count:=0;
try
Repeat
InternetReadFile(H2, @Buffer, SizeOf(Buffer), Count);
Count:=FileWrite(H3, Buffer, Count);
Until Count<=0;
finally
FileClose(H3);
end;
finally
InternetCloseHandle(H2);
end;
finally
InternetCloseHandle(H1);
end;
end;
procedure InternetZagruzitFajl2(URL, f: string);
const MaxBuffer=65536;
var LoadStream: TMemoryStream;
idHTTP1: TIdHTTP;
H3: integer;
Count: cardinal;
Buffer: array[1..MaxBuffer] of char;
begin
LoadStream:=TMemoryStream.Create;
idHTTP1:=TIdHTTP.Create(Application);
try
idHTTP1.Get(URL, LoadStream);
except
LoadStream.Free;
idHTTP1.Free;
Exit;
end;
H3:=FileCreate(f);
If H3=-1 then
begin
LoadStream.Free;
idHTTP1.Free;
Exit;
end;
FileSeek(H3, 0, 0);
LoadStream.Seek(0, 0);
Repeat
Count:=LoadStream.Read(Buffer, MaxBuffer);
If Count>0 then
FileWrite(H3, Buffer, Count);
Until Count<=0;
FileClose(H3);
LoadStream.Free;
idHTTP1.Free;
end;
procedure TForm1.Button1Click(Sender: TObject);
const URL='http://newerow1989.narod.ru/list.txt';
f1='E:\list1.txt';
f2='E:\list2.txt';
begin
InternetZagruzitFajl1(URL, f1);
InternetZagruzitFajl2(URL, f2);
end;
где
URL - URL-файл в Интернете, который нужно скачать;
f - полное имя файла, сохраняемого на компьютере.
|