Recent

Author Topic: Updating a program via ftp (Windows)  (Read 1358 times)

Selzig

  • New member
  • *
  • Posts: 9
Updating a program via ftp (Windows)
« on: August 26, 2024, 01:47:13 pm »
Hello,

Is there a component that would allow a program developed with Lazarus to be updated on Windows when launched (with a new version of the exe placed on an ftp server) ?

Regards. Slz

Zvoni

  • Hero Member
  • *****
  • Posts: 3396
Re: Updating a program via ftp (Windows)
« Reply #1 on: August 27, 2024, 09:21:22 am »
Hello,

Is there a component that would allow a program developed with Lazarus to be updated on Windows when launched (with a new version of the exe placed on an ftp server) ?

Regards. Slz
AFAIK, No, since that has nothing to do with Lazarus itself (or any other language for that matter).
If you execute your Program, that executable is "locked" (as in it cannot be deleted/overwritten).
You need to write a separate program that does the "update"
Kinda like
1) You start your program
2) your program calls this "other" program called CheckForUpdate (or whatever) --> Keyword TProcess (?) and IPC
3) This other Program actually does the check if a new version is available
4) if yes, this other program terminates your program, downloads the new version to its correct location, executes the new version, and then terminates itself

That said: I might be completely wrong.....
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad

af0815

  • Hero Member
  • *****
  • Posts: 1409
Re: Updating a program via ftp (Windows)
« Reply #2 on: August 27, 2024, 10:50:50 am »
BTW: Look at Lazarus und recompiling.

Lazarus.exe and StartLazarus.exe are working together to update Lazarus itself after the recompiling.
regards
Andreas

paweld

  • Hero Member
  • *****
  • Posts: 1637
Re: Updating a program via ftp (Windows)
« Reply #3 on: August 27, 2024, 12:00:45 pm »
There is a component for automatic updates, but it does not support FTP: https://wiki.freepascal.org/LazAutoUpdater
You can also do it yourself, use synapse to communicate with FTP: https://wiki.freepascal.org/Synapse
Both packages can be installed using OPM
Code: Pascal  [Select][+][-]
  1. uses
  2.   ftpsend;
  3.  
  4. procedure TForm1.Button1Click(Sender: TObject);
  5. begin
  6.   if UpdateAvailable then
  7.   begin
  8.     //gent new file from ftp
  9.     //replace app file
  10.   end;
  11. end;
  12.  
  13. function TForm1.UpdateAvailable: Boolean;
  14. var
  15.   local_ver, remote_ver: TDateTime;
  16.   lver, rver, local_info_filename: String;
  17.   sl: TStringList;
  18.   fs: TFormatSettings;
  19. begin
  20.   Result := False;
  21.   fs.ShortDateFormat := 'yyyy/mm/dd';
  22.   fs.ShortTimeFormat := 'hh:nn:ss';
  23.   fs.DateSeparator := '/';
  24.   fs.TimeSeparator := ':';
  25.   lver := {$i %date%} + ' ' + {$i %time%}; //date and time of compilation
  26.   if not TryStrToDateTime(lver, local_ver, fs) then
  27.   begin
  28.     ShowMessage('Unknown local version');
  29.     exit;
  30.   end;
  31.   local_info_filename := GetTempDir + 'myapp_version_infp.txt';
  32.   //on the ftp must be a file named “myapp_verion_info.txt”,
  33.   //which in the first line will contain the date and cas of the current version of the program
  34.   if not FtpGetFile('ftp_server', 'ftp_port', 'myapp_verion_info.txt', local_info_filename, 'ftp_user', 'ftp_password') then
  35.   begin
  36.     ShowMessage('Unable to check remote version info');
  37.     exit;
  38.   end;
  39.   sl := TStringList.Create;
  40.   sl.LoadFromFile(local_info_filename);  
  41.   rver := sl[0];
  42.   sl.Free;
  43.   if not TryStrToDateTime(rver, remote_ver) then
  44.   begin
  45.     ShowMessage('Unknown remote version');
  46.     exit;
  47.   end;
  48.   Result := remote_ver > local_ver;
  49. end;    
  50.  
Best regards / Pozdrawiam
paweld

 

TinyPortal © 2005-2018