How to copy file to web lazarus / 21-General ---------------------------------------------------------------------- bobonwhidbey · 2024-12-13 19:10 i have no problem downloading files from my website using fphttpclient. I'd like some help writing a file back to my web site. This is the sample coding I saw Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i function PutFileContent(URL: string; Response: TStream): boolean;begin  Result := False;  with TFPHttpClient.Create(nil) do  try    Put(URL, Response);    Result := True;  finally    Free;  end;end; but it gives an error ..exception class 'EHTTPClient' with message Invalid protocol: "C" For sure I would need a Username and Password, perhaps some other info, but it's not clear how to provide that. What's an easy way to write a file to my web site? Does it depend on text or binary file? ---------------------------------------------------------------------- Warfley · 2024-12-13 22:25 It depends, how is the Website upload function implemented? If the http server does not implement a way to upload files via post or put you can't use it that way ---------------------------------------------------------------------- TRon · 2024-12-13 22:33 As warfley already mentioned. Since it is your website  you would have to implement functionality for being able to upload files (or make use with whatever CMS is in place). Usually hosting companies offer shell or ftp access which you can use for maintenance (including uploading files). ---------------------------------------------------------------------- bobonwhidbey · 2024-12-13 22:44 I can upload files using Filezilla or FireFTP without a problem. I want to upload them using a Laz app. ---------------------------------------------------------------------- TRon · 2024-12-13 23:21 Is your aim to let users of your website be able to upload files (including yourself) or is it only meant for you (the owner of the website) to be able to update your website (e.g. upload html pages, pictures , php scripts etc) ? In case the latter you can use ftps or sftp protocol to upload files (the choice depends on what protocol  your host supports, see your filezilla/fireFTP settings ) . In case the former there is need to have something running on your server that is able to accept file uploads. Depending on the answer(s) there are different paths to take. ---------------------------------------------------------------------- bobonwhidbey · 2024-12-14 02:46 My aim was to have an app that I and my spouse could use to upload files to the web ---------------------------------------------------------------------- lainz · 2024-12-14 04:09 You can use ftp with your web server credentials. Or create a php script to upload files. Ensure that it has at least a token as authentication. ---------------------------------------------------------------------- bobonwhidbey · 2024-12-14 06:48 I thought the best way to do that with Laz was to use FTPSend - but that unit is no longer in Laz (if it every was) and I can't figure out how to do it inside a Windows Laz program.  I now think I want to use something in the fphttpclient unit. ---------------------------------------------------------------------- TRon · 2024-12-14 06:56 Quote from: bobonwhidbey on December 14, 2024, 07:48:09 am... Laz was to use FTPSend - but that unit is no longer in Laz (if it every was) ... It is a unit of the synapse project. see also github. You can install it in Lazarus using OPM. Other than that, and perhaps you do not realize, your hints are vague at best. You have a webserver running so you ought to now what you run there and how to access. There are literally dozens of methods to 'upload' files to a webserver ranging from sending e-mails, remote shell access to running a dedicated service. Each method requires another approach. As an example, this forum software allows for attaching files that are being uploaded when you press the send message button. In order to let that work a http server is running on the webserver, along with some scripts that know what to do with those attached files when a user presses that send message link. fphttpclient can be used in situations where a service runs on your website that actually accepts files (and know what to do with it, in case of 'sending' files). As long as you do not have anything hosted in that department the use of fphttpclient will be in vain. Since you mentioned being able to access the server with an ftp client that means that your hosting provider at least grants ftp access, so the focus should be on that, Plenty of examples available either provided by synapse or here in the forums (and synapse is only one of several options) but.... it is important to know whether the server should be accessed using sftp or ftps as the actual implementation depends on it.. ---------------------------------------------------------------------- bobonwhidbey · 2024-12-14 20:20 A function that looks like something that would work is in the FTPAPI unit Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i Function FtpPut(Host, UserId, Passwd, Acct, Local, Remote: PChar; TransferType: Integer): Integer; cdecl; However, unit can't be compiled because it uses OS2Def and PMWin which are no where to be found. This FTPAPI unit is more than 20 years old and has probably been superceded. Perhaps there's a component that will achieve the same end. This thread from last summer seems to ask a very similar question https://forum.lazarus.freepascal.org/index.php?topic=25066.0 ---------------------------------------------------------------------- dseligo · 2024-12-14 23:36 Why don't you use Synapse as Tron told you? Then you can use FTP like this: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i uses ... ftpsend ......with TFTPSend.Create dotry  Username := 'username';  Password := 'password';  TargetHost := 'host';  TargetPort := 'port';  if not Login then Exit;  If not ChangeWorkingDir('remote directory') then    Exit;  DirectFileName := 'source file';  DirectFile:=True;  Result := StoreFile('destination file', False);  Logout;finally  Free;end; ---------------------------------------------------------------------- bobonwhidbey · 2024-12-14 23:46 That's exactly solution I'm trying to use. However, I can not find ftpsend anywhere.  I've loaded synapse from the OPM but there is no ftpsend.pas file anywhere on my PC.  Do I need to download that file from some other source? ---------------------------------------------------------------------- TRon · 2024-12-14 23:55 Did you add synapse as dependency in the project manager of your project ? ---------------------------------------------------------------------- Remy Lebeau · 2024-12-15 00:18 Indy is also in OPM, and it has a TIdFTP component. ---------------------------------------------------------------------- dseligo · 2024-12-15 00:48 Quote from: bobonwhidbey on December 15, 2024, 12:46:49 amThat's exactly solution I'm trying to use. However, I can not find ftpsend anywhere.  I've loaded synapse from the OPM but there is no ftpsend.pas file anywhere on my PC.  Do I need to download that file from some other source? You probably just need to add laz_synapse to Required Packages in Project Inspector, like Tron said. But it is strange what you said that you can't find ftpsend anywhere. Open OPM, then click on "Local repo" button, and then you should see synapse40.1 directory. ftpsend.pas should be in it. ---------------------------------------------------------------------- egsuh · 2024-12-16 02:53 QuoteYou probably just need to add laz_synapse to Required Packages in Project Inspector, like Tron said. This is right. I use httpsend instead of ftpsend. The file name could be httpsend.pp, not httpsend.pas, etc. Not sure. But once the laz_synapse is included in the required packages, you won't try to find the position of the file. With httpsend, I attach an example of uploading file.  Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i uses HttpSend;...function Taq_r_5.UploadImage(tpid, filename: string;out Msg: string): boolean;var   AStrm: TMemoryStream;   AStrl : TStringList;   tfn: string;begin   Result:= false;    if FileExists(filename) then begin      tfn := tpid + ExtractFileExt(filename);  // this is to process the filename at server end.       AStrm := TMemoryStream.Create;      AStrl := TStringList.Create;    // This is to receve returned Webserver content       try          AStrm.LoadFromFile(filename);          Result := HttpPostFile(URL + 'UploadImage', tpid, tfn, AStrm, AStrl);                           // (URL, FieldName, FileName, Data, ResultData)        Msg := trim(astrl.text);  // astrl.text is returned text from server          Result:= Msg = tfn;   // My webserver returns the filename if everything is done correctly.       finally        AStrl.Free;        AStrm.Free;      end;   end   else Result := False;end;  The function to call is       HttpPostFile(URL, FieldName, FileName, FileStream, ReturnStrings) Here, parameters are : - URL  : the URL that receives the file - FieldName:  As this is "post" method, there is a fieldname. In HTML example of  , it is the value of "name". - FileName :  This is your local file name. It does not mean that this filename will be used by server to save the file, depending on the server side. Anyway it's server's role. - File stream: the stream of file that you want to upload. - RetrunStrings :  the returned texts from webserver will be stored here, as TStrings. Hope this is helpful.  Msg, tfn, etc. are for my own purposes.