(SOLVED) FTP download in memory lazarus / 38-Networking and Web Programming ---------------------------------------------------------------------- xinyiman · 2016-06-06 09:39 Hello guys, does anyone have an example of an FTP download with synapse but that does not create the file but rather charge me the downloaded image directly into a TPicture? In short working only in RAM to be faster. Thank you ---------------------------------------------------------------------- balazsszekely · 2016-06-06 10:11 With Indy you can. There is an overloaded version of IdFTP.Get method which accepts as parameter a stream: 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 procedure Get(const ASourceFile: string; ADest: TStream; AResume: Boolean = false); overload;Looking at the synapse code, I see the FtpGetFile function, which internally use the RetriveFile then the DataRead method. DataRead accepts a stream parameter, so in theory it's possible but you have to do a little work. ---------------------------------------------------------------------- rvk · 2016-06-06 10:15 Just set DirectFile to false. It will use the FDataStream (TMemoryStream) to read the file in memory. You'll have to do 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; function ReadFtpToImage(const IP, Port, FileName, User, Pass: string; Image1: TImage): boolean;begin  Result := False;  with TFTPSend.Create do    try      if User <> '' then      begin        Username := User;        Password := Pass;      end;      TargetHost := IP;      TargetPort := Port;      if not Login then Exit;      DirectFileName := 'dummyfilename';      DirectFile := False;     // <------ Important !!      Result := RetrieveFile(FileName, False);     if Result then        Image1.Picture.LoadFromStream(DataStream);     Logout;    finally      Free;    end;end; ---------------------------------------------------------------------- xinyiman · 2016-06-07 06:39 Ok rvk, it works great , and if I wanted to do it reverse ? That is, send to FTP the contents of a TImage component ? ---------------------------------------------------------------------- rvk · 2016-06-07 08:12 I've taken the source of FtpGetFile() to create the ReadFtpToImage. So for the reverse you could have taken the FtpPutFile() and done the same. Here is a (non-tested) example: 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; // source taken from FtpPutFile()function WriteImageToFtp(const IP, Port, FileName, User, Pass: string; Image1: TImage): boolean;begin  Result := False;  with TFTPSend.Create do    try      if User <> '' then      begin        Username := User;      Password := Pass;      end;      TargetHost := IP;      TargetPort := Port;      if not Login then Exit;      DirectFileName := 'dummyfilename';      DirectFile := False;        // <------ Important !!       Image1.Picture.SaveToStream(DataStream); // <-- this saves the image to ftp-stream       Result := StoreFile(FileName, False); // and transfers it to Filename on ftp server      Logout;    finally    Free;    end;end; ---------------------------------------------------------------------- xinyiman · 2016-06-07 09:20 But with the ' last example I refer to the file What ftp server resides on HD , I want to pass the content of image , then RAM to FTP ---------------------------------------------------------------------- rvk · 2016-06-07 09:23 Yes, that's what the WriteImageToFtp() I showed you does. It does the reverse from the previous ReadFtpToImage(). You supply WriteImageToFtp with a filename to store on the FTP side and the TImage with content. It will take the content of that TImage and store it on the FTP-side in Filename. ---------------------------------------------------------------------- xinyiman · 2016-06-07 11:04 You're right , it works well . thank you so much