Kamis, 02 Juni 2022

Lazarus FTP Send – synapse40

Kebutuhan :

-Lazarus 2.0.1 32bit

-FPC 3.2.0

-Synapse40

-file “uFTP.pas”

 

Cara :

1.buka menu : Package > Open Package File (.lpk)

2.cari file laz_synapse.lpk



3.buka menu Use > Add to Project



4. pada uses tambahkan unit “ftpsend”

5.pada uses tambahkan unit “uFTP”

6.isi parameter berikut :  ftpHost, ftpUserID, ftpPassword

7. kemudian panggil function :

function FTPSendFile(LocalFile: string; RemoteFile: string;RemoteDir: string): boolean;

 

keterangan :

LocalFile = alamat file yg akan dikirim ke server

RemoteFile=nama file setelah berada deserver

RemoteDir= nama/alamat folder dibawah root


unit uFTP;

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils,ftpSend;


function FTPSendFile(LocalFile: string; remoteFile: string;RemoteDir: string): boolean;

var
 ftpHost:String;
 ftpUserID:String;
 ftpPassword:String;

 FTPClient:TFTPSend;

implementation


function FTPSendFile(LocalFile: string; remoteFile: string;RemoteDir: string): boolean;
var
   rc : boolean;
begin
   FTPClient := TFTPSend.Create;
   with FTPClient do
   begin
      TargetPort  := cFtpProtocol;
      TargetHost := ftpHost;
      UserName := ftpUserID;
      Password := ftpPassword;

      if not LogIn then exit;

      DirectFileName := LocalFile;
      DirectFile := True;

      if RemoteDir <> '' then ChangeWorkingDir(RemoteDir);

      rc := StoreFile(RemoteFile,false);

      LogOut;
      free;
   end;
   Result := rc;
end;


end.