FTP lazarus / 38-Networking and Web Programming ---------------------------------------------------------------------- xinyiman · 2016-02-17 21:20 There is a working example of an ftp file transfer? ---------------------------------------------------------------------- JanRoza · 2016-02-17 23:14 Something 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; var  strFtpIni: String = '/httpdocs//';  strFTPHost: String = 'server.domain.com';  strFTPuser: String = '';  strFTPpw: String = '';   with TFTPSend.Create do  try    Username := strFTPuser;     Password := strFTPpw;    TargetHost := strFTPHost;    TargetPort := '21';     DirectFileName := ;    DirectFile := True;    RetrieveFile(strFtpIni, False);    end;  finally    Free;  end; ---------------------------------------------------------------------- Thaddy · 2016-02-18 08:42 Or even this (also with synapse)? 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 program simpleftp;{$apptype console}{$ifdef fpc}{$mode delphi}{$endif}uses ftpsend;begin  if ftpGetFile('','21','',                   '',                     ','') then    writeln('succes') else writeln('fail');  readln;end.  If you want to send a file, just change ftpGetFile into ftpPutFile. The syntax is the same. ---------------------------------------------------------------------- xinyiman · 2016-02-18 21:48 I tried with this function and goes well with individual files. But if I want to send an entire directory with subdirectories? 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 TForm1.Send(fHost: string; fUserID: string; fPassword: string; LocalFile : string; remoteFile : string; RemoteDir : string) : boolean ;//=================================================================== ========//     ******************************************************* ***************//     * Send a file to the FTP server                                    *//     ****************************************** ****************************//---------------------------------------- -----------------------------------var   rc : boolean;   FTPClient : TFTPSend;begin   // Create the FTP Client object and set the FTP parameters   FTPClient := TFTPSend.Create;   with FTPClient do begin    TargetPort  := '21';      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; ---------------------------------------------------------------------- SymbolicFrank · 2016-02-22 16:24 Use FindAllFiles to make a list. ---------------------------------------------------------------------- Graeme · 2016-02-24 12:37 There are many examples of FTP usage in these forums. Please use the Search  functionality to find more examples using FPC only, Synapse, Indy 10 etc. ---------------------------------------------------------------------- evresis · 2021-06-09 20:20 What happens if the command PASV (when FTP.Passive:=true) is returned to a private address by mistake on the remote server firewall config? eg'227 Entering Passive Mode (192,168,148,37,129,44)'. We receiving error 425 can't open data connection! I am using synapse 4.0 and Lazarus 2.0.10. In most famous ftp clients (filezilla,winscp etc) user can replace or better force the public ip of remote server before send a data command to ftp server. With few code line addition to Class TFTPSend in unit ftpsend we can reestablish lost data connection. a) Add a boolean variable to protected part of class eg 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 FForceIP: Boolean;b) Add a boolean property to published part of class eg 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 property ForceIP: Boolean read FForceIP write FForceIP; permits to change the above variable c) At 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 TFTPSend.DataSocket: boolean; after the command 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 FDSock.CloseSocket; in passive mode first part of function adding the following command 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 if FForceIP then FDataIP:=FTargetHost; that replaces private IP given by PASV command with the IP of remote ftp server. d) To enable force remote host IP address just set 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 FTP.Passive:= True; and 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 FTP.ForceIP:= True;. Τhe data channel is now returning and operating normally! ---------------------------------------------------------------------- Vodnik · 2023-05-25 19:43 Thanks, evresis! You code have solved problem with my trivial application that was hanging after call to TFTPSend.List('',False).