пытаюсь скачать файл размером 5200000 байт с сайта на narod.ru Использовал функции:| Код | function DownloadFile(const Url: string): string;
var
NetHandle: HINTERNET;
UrlHandle: HINTERNET;
Buffer: array[0..1024] of char;
BytesRead: cardinal;
begin
Result := '';
NetHandle := InternetOpen('Delphi 5.x', 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
{ UrlHandle правильный? Начинаем загрузку }
begin
FillChar(Buffer, SizeOf(Buffer), 0);
repeat
Result := Result + Buffer;
FillChar(Buffer, SizeOf(Buffer), 0);
InternetReadFile(UrlHandle, @Buffer, SizeOf(Buffer), BytesRead);
until BytesRead = 0;
InternetCloseHandle(UrlHandle);
end
else
begin
{ UrlHandle неправильный. Генерируем исключительную ситуацию. }
raise Exception.CreateFmt('Cannot open URL %s', [Url]);
end;
InternetCloseHandle(NetHandle);
end
else
{ NetHandle недопустимый. Генерируем исключительную ситуацию }
raise Exception.Create('Unable to initialize Wininet');
end;
...
begin AssignFile(f,'C:\1.txt');//запихиваю в текстовый файл rewrite(f); write(f,DownloadFile('http://blackkot32.narod.ru/DOTU/01_vvodnaia_1/20.txt')); CloseFile(f); end;
|
и вторая| Код | procedure DLFile(DwFile, SvFile: string); var hInternet: pointer; hFile: pointer; DataBuff: pointer; Size, Bytes: dword; hOut: dword; begin try try hInternet := InternetOpen(nil, INTERNET_OPEN_TYPE_PRECONFIG, nil, nil, 0); hFile := InternetOpenUrl(hInternet, PChar(DwFile), nil, 0, INTERNET_FLAG_EXISTING_CONNECT, 0); if hFile <> nil then begin InternetQueryDataAvailable(hFile, Size, 0, 0); GetMem(DataBuff, Size); try InternetReadFile(hFile, DataBuff, Size, Bytes); hOut := CreateFile(PChar(SvFile), GENERIC_WRITE, 0, nil, CREATE_ALWAYS, $20, 0); if hOut <> INVALID_HANDLE_VALUE then begin WriteFile(hOut, DataBuff^, Size, Bytes, nil); CloseHandle(hOut); end finally FreeMem(DataBuff); end; end; except MessageBox(0,'Íå ìîãó ïîäêëþ÷èòüñÿ ê ñåðâåðó','',MB_OK); end; finally InternetCloseHandle(hFile); MessageBox(0,pchar('ñêà÷àë '+inttostr(Size)),'',MB_OK); end; InternetCloseHandle(hInternet); end;
...
DLFile('http://blackkot32.narod.ru/DOTU/01_vvodnaia_1/20.txt','C:\0!.txt')
|
в обоих случаях файл не докачивается чтоли, его размер меньше. иль я его не правильно сохраняю? |