function GetInetFile(fileURL, FileName: String): boolean;
const BufferSize = 1024;
var
hSession, hURL: HInternet;
Buffer: array[1..BufferSize] of Byte;
BufferLen: DWORD;
f: File;
sAppName: string;
begin
Result:=False;
hSession := InternetOpen(PChar('IE'),
INTERNET_OPEN_TYPE_PRECONFIG,
nil, nil, 0);
try
hURL := InternetOpenURL(hSession,
PChar(fileURL),
nil,0,0,0);
try
AssignFile(f, FileName);
Rewrite(f,1);
repeat
InternetReadFile(hURL, @Buffer,
SizeOf(Buffer), BufferLen);
BlockWrite(f, Buffer, BufferLen)
until BufferLen = 0;
CloseFile(f);
Result:=True;
finally
InternetCloseHandle(hURL)
end
finally
InternetCloseHandle(hSession)
end
end;
function CheckInetUrlExist(url: string): boolean;
var
NetHandle: HINTERNET;
UrlHandle: HINTERNET;
begin
Result := False;
NetHandle := InternetOpen(PChar('IE'), INTERNET_OPEN_TYPE_PRECONFIG, nil, nil, 0);
if Assigned(NetHandle) then begin
UrlHandle := InternetOpenUrl(NetHandle, PChar(Url), nil, 0, INTERNET_FLAG_RELOAD, 0);
if Assigned(UrlHandle) then begin
Result := True;
End;
End;
InternetCloseHandle(NetHandle);
InternetCloseHandle(UrlHandle);
end;
в твоем случае:
If CheckInetUrlExist('http://www.mysyte.ru/text.txt') then GetInetFile('http://www.mysyte.ru/text.txt', 'c:\temp\text.txt');