Forum > Networking and Web Programming

FTP

(1/2) > >>

xinyiman:
There is a working example of an ftp file transfer?

JanRoza:
Something like this?


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---uses FTPSend; var  strFtpIni: String = '/httpdocs/<Folder name>/<File name>';  strFTPHost: String = 'server.domain.com';  strFTPuser: String = '<User name>';  strFTPpw: String = '<Password>';   with TFTPSend.Create do  try    Username := strFTPuser;     Password := strFTPpw;    TargetHost := strFTPHost;    TargetPort := '21';     DirectFileName := <Target filename>;    DirectFile := True;    RetrieveFile(strFtpIni, False);    end;  finally    Free;  end; 

Thaddy:
Or even this (also with synapse)?

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---program simpleftp;{$apptype console}{$ifdef fpc}{$mode delphi}{$endif}uses ftpsend;begin  if ftpGetFile('<domain_or_ip>','21','<remote_file_name_plus_path>',                     '<target_filename_plus_path>',                     '<username'>,'<password>') 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:
I tried with this function and goes well with individual files. But if I want to send an entire directory with subdirectories?


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---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:
Use FindAllFiles to make a list.

Navigation

[0] Message Index

[#] Next page

Go to full version