-



DrBob FTP


WinInet , "internet handle" ( Windows handles), API . , WinInet , InternetOpen, , ( API ). , InternetCloseHandle ( , try-finally, finally).

( URL) , InternetOpenURL, . , (URL) , InternetReadFile, BlockRead, . BlockWrite , WinInet (, InternetCloseHandle), , FTP :

program

DrBobFTP;

{$APPTYPE CONSOLE}

{$I+}

uses

Windows, WinInet;

procedure

CopyURL(const URL, OutputFile: String);

const

BufferSize = 1024;

var

hSession, hURL: HInternet;

Buffer: Array[0..Pred(BufferSize)] of Byte;

BufferLength: DWORD;

f: File;

begin

hSession := InternetOpen('DrBob',INTERNET_OPEN_TYPE_PRECONFIG,nil,nil,0);

try

hURL := InternetOpenURL(hSession, PChar(URL), nil,0,0,0);

try

Assign(f, OutputFile);

Rewrite(f,1);

repeat

InternetReadFile(hURL, @Buffer, BufferSize, BufferLength);

write('.');

BlockWrite(f, Buffer, BufferLength)

until

BufferLength = 0;

Close(f);

writeln('OK') { if we get here, we succeeded }

finally

InternetCloseHandle(hURL)

end

finally

InternetCloseHandle(hSession)

end

end;

begin

if

ParamCount <2 >then

begin

writeln('Usage: DrBobFTP URL Filename');

writeln('Example: DrBobFTP http://www.drbob42.com/ftp/headconv.zip hc.zip')

end

else

CopyURL(ParamStr(1), ParamStr(2))

end.

, WinInet.DLL, Microsoft web .