[SOLVED] Synapse - How to simply make a file upload? lazarus / 38-Networking and Web Programming ---------------------------------------------------------------------- lazguy · 2011-10-07 17:36 Hallo Everybody !!!!!!!!!!!!! I am using the following procedure to download a file: Code: [Select]procedure DownloadFile(const Url, PathToSaveTo: string); begin    fs := TFileStream.Create(PathToSaveTo, fmOpenWrite or fmCreate);    try       HttpGetBinary(Url, fs);    finally       fs.Free;    end; end; How to do the same to upload a file (maybe FTP ? username and password ? or HTTP ? or other way ?) Please, write the code like the one above. Thank you very much in advance !!!! ---------------------------------------------------------------------- Arbee · 2011-10-07 19:25 This is a function I use for FTP upload.  I had to strip quite a few things not relevant for you, so I hope I haven't broken anything.  You should add some displaying here and there, but this was the core ... Code: [Select]function TModel.Send(LocalFile : string; remoteFile : string; RemoteDir : string) : boolean; //==================================================================== ======= //     *************************************************************** ******* //     * Send a file to the FTP server                                    * //     *************************************************************** ******* //-------------------------------------------------------------------- ------- var    rc : boolean; begin    // Create the FTP Client object and set the FTP parameters    FTPClient := TFTPSend.Create;    with FTPClient do begin       TargetPort  := cFtpProtocol;       TargetHost := fHost;  // these were properties set somewhere else       UserName := fUserID;       Password := fPassword;       //-------------------------------------------------------------- ---------       // bail out if the FTP connect fails       if not LogIn then exit;       //-------------------------------------------------------------- ----------       // Set filename to FTP       DirectFileName := LocalFile;       DirectFile := True;       //-------------------------------------------------------------- ----------       // change directory if requested       if RemoteDir <> '' then ChangeWorkingDir(RemoteDir);       //-------------------------------------------------------------- ----------       // STOR file to FTP server.        rc := StoreFile(RemoteFile,false);       //-------------------------------------------------------------- ----------       // close the connection       LogOut;       //-------------------------------------------------------------- ----------       // free the FTP client object       free;       //-------------------------------------------------------------- ----------    end;    Result := rc; //==================================================================== ======= end; ---------------------------------------------------------------------- lazguy · 2011-10-13 00:30 Thank You Very, Very Much, Arbee !!!!!! Perfect !!!!!!! Solved. ---------------------------------------------------------------------- DiCri · 2016-07-18 09:44 Quote from: Arbee on October 07, 2011, 09:25:54 pmThis is a function I use for FTP upload.  I had to strip quite a few things not relevant for you, so I hope I haven't broken anything.  You should add some displaying here and there, but this was the core ... Code: [Select]function TModel.Send(LocalFile : string; remoteFile : string; RemoteDir : string) : boolean; //==================================================================== ======= //     *************************************************************** ******* //     * Send a file to the FTP server                                    * //     *************************************************************** ******* //-------------------------------------------------------------------- ------- var    rc : boolean; begin    // Create the FTP Client object and set the FTP parameters    FTPClient := TFTPSend.Create;    with FTPClient do begin       TargetPort  := cFtpProtocol;       TargetHost := fHost;  // these were properties set somewhere else       UserName := fUserID;       Password := fPassword;       //-------------------------------------------------------------- ---------       // bail out if the FTP connect fails       if not LogIn then exit;       //-------------------------------------------------------------- ----------       // Set filename to FTP       DirectFileName := LocalFile;       DirectFile := True;       //-------------------------------------------------------------- ----------       // change directory if requested       if RemoteDir <> '' then ChangeWorkingDir(RemoteDir);       //-------------------------------------------------------------- ----------       // STOR file to FTP server.        rc := StoreFile(RemoteFile,false);       //-------------------------------------------------------------- ----------       // close the connection       LogOut;       //-------------------------------------------------------------- ----------       // free the FTP client object       free;       //-------------------------------------------------------------- ----------    end;    Result := rc; //==================================================================== ======= end; Uses??? ---------------------------------------------------------------------- rvk · 2016-07-18 10:05 Quote from: Manu12x on July 18, 2016, 11:44:15 amUses??? ftptsend. Download the library at http://www.ararat.cz/synapse/doku.php/download (specifically the SVN version. Click the download snapshot button at https://sourceforge.net/p/synalist/code/HEAD/tree/trunk/) Open your project. Choose Package > Open Package File and choose laz_synapse.lpk and Compile and Use > Add to project. Now include ftpsend to your uses clause in the unit you have this snippet in. ---------------------------------------------------------------------- DiCri · 2016-07-18 10:22 Quote from: rvk on July 18, 2016, 12:05:06 pmQuote from: Manu12x on July 18, 2016, 11:44:15 amUses??? ftptsend. Download the library at http://www.ararat.cz/synapse/doku.php/download (specifically the SVN version. Click the download snapshot button at https://sourceforge.net/p/synalist/code/HEAD/tree/trunk/) Open your project. Choose Package > Open Package File and choose laz_synapse.lpk and Compile and Use > Add to project. Now include ftpsend to your uses clause in the unit you have this snippet in. Can i use this unit on Free Pascal? And if yes where i can find a tutorial for installation? Because i tried with other units but installing always gives error ---------------------------------------------------------------------- rvk · 2016-07-18 10:24 Quote from: Manu12x on July 18, 2016, 12:22:07 pmCan i use this unit on Free Pascal? And if yes where i can find a tutorial for installation? Because i tried with other units but installing always gives error You don't need to "install" this library. You can just "use" it. (there is also no "install" option under "Use" in Lazarus. only "Add to project".) And yes, you can use it in Free Pascal. In that case you just need to add the path to the library source files and include the ftpsend in the uses. FPC will find it and compile all necessary files. What errors are you getting. ---------------------------------------------------------------------- DiCri · 2016-07-18 11:06 Oh ok  so this unit is simply to add.. I tried to install ZenGL graphics but it tells that there are errors in the syntax of the demo code for free pascal.. But now it doesn't matter. I should add ftpsend and see if it works