Recent

Author Topic: Download files using LNET  (Read 5193 times)

Zittergie

  • Full Member
  • ***
  • Posts: 114
    • XiX Music Player
Download files using LNET
« on: December 05, 2010, 12:45:07 pm »
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);
Code: [Select]
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;
Code: [Select]
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);
Code: [Select]
procedure TFormUpdate.HTTPClientDoneInput(aSocket: TLHTTPCLientSocket);
begin
  aSocket.Disconnect;
  CloseFile(TempFile); DownLoadDone:=True; ShowMessage('Hallo Done');
end;
   

Please someone help me out ...
Be the difference that makes a difference

Zittergie

  • Full Member
  • ***
  • Posts: 114
    • XiX Music Player
Re: Download files using LNET
« Reply #1 on: December 05, 2010, 04:10:02 pm »
I have tried SYNAPSE now.  It seems easier to use.
Downloading works like a charm.

Tested under Linux.

Does anyone know if this works under MacOS too?  The website only mentions Linux and Windows.
Be the difference that makes a difference

 

TinyPortal © 2005-2018