Hello,
It has been asked a few times here on the board, but I can't seem to find an answer that suits me.
I have developed a program that uses WGET or CURL to check for files on my webserver so I can update the application.
I would now like to ditch the use of WGET or CURL and use internal procedure.
The procedure has to work in LINUX, WINDOWS and MACOS and has to download simple TEXT-files, JPG-files and the aaplication itself.
I have found LNET, but there is not much documentation on how to use it.
I would like to make a procedure like: DOWNLOAD(Source, Target: String);
I succeed in downloading a file using LNET, but the download goes on after starting the procedure.
So opening a second download or opening the downloaded file fails, because the file is still open and being downloaded.
I do not find how to wait until: 1) The download finished or 2) The download failed.
The Testcase:
I need to download '
http://www.zittergie.be/update/ccatalog/UPDATE.DAT' & '
http://www.zittergie.be/update/ccatalog/FOTOS.DAT'
These files are the processed and depending on the outcome, more files need to be downloaded.
What I have now: (Test setup)
procedure DOWNLOAD(Source, target: string);
procedure TFormUpdate.Download(Source, Target: string);
var
aHost, aURI: string;
aPort: Word;
begin
DownloadError:=0;
AssignFile(TempFile,Target);
Rewrite(TempFile);
HTTPBuffer := '';
SSL.SSLActive := DecomposeURL(Source, aHost, aURI, aPort);
HTTPClient.Host := aHost;
HTTPClient.URI := aURI;
HTTPClient.Port := aPort;
HTTPClient.SendRequest;
end;
Procedure HTTPClientInput(ASocket: TLHTTPClientSocket; ABuffer: pchar;
ASize: dword): dword;
function TFormUpdate.HTTPClientInput(ASocket: TLHTTPClientSocket; ABuffer: pchar;
ASize: dword): dword;
var
oldLength: dword;
begin
oldLength := Length(HTTPBuffer);
setlength(HTTPBuffer,oldLength + ASize);
move(ABuffer^,HTTPBuffer[oldLength + 1], ASize);
write(TempFile,HTTPBuffer);
Result := aSize; // tell the http buffer we read it all
end;
procedure HTTPClientDoneInput(aSocket: TLHTTPCLientSocket);
procedure TFormUpdate.HTTPClientDoneInput(aSocket: TLHTTPCLientSocket);
begin
aSocket.Disconnect;
CloseFile(TempFile); DownLoadDone:=True; ShowMessage('Hallo Done');
end; Please someone help me out ...