Pascal (Lazarus/Delphi)
Pascal (Lazarus/Delphi)
FTP Upload / Download to a BinData Object
Demonstrates how to FTP upload the contents of a BinData object, and FTP downloads to the a BinData object.Chilkat Pascal (Lazarus/Delphi) Downloads
program ChilkatDemo;
// Demonstrates using the Chilkat Pascal wrapper via the C bridge DLL.
// Builds as a console application under Lazarus (FPC) or Delphi.
{$IFDEF FPC}
{$MODE DELPHI}
{$ENDIF}
{$APPTYPE CONSOLE}
uses
{$IFDEF UNIX}
cthreads,
{$ENDIF}
SysUtils,
CkDllLoader,
Chilkat.Ftp2,
Chilkat.BinData;
// ---------------------------------------------------------------------------
procedure RunDemo;
var
success: Boolean;
ftp: TFtp2;
bdA: TBinData;
remoteFilename: string;
bdB: TBinData;
begin
success := False;
// This example assumes Chilkat Ftp2 to have been previously unlocked.
// See Unlock Ftp2 for sample code.
ftp := TFtp2.Create;
ftp.Hostname := 'www.my-ftp-server.com';
ftp.Username := 'mFtpLogin';
ftp.Password := 'myFtpPassword';
// Connect to the FTP server.
success := ftp.ConnectOnly();
if (success <> True) then
begin
WriteLn(ftp.LastErrorText);
Exit;
end;
// Authenticate with the FTP server.
success := ftp.LoginAfterConnectOnly();
if (success <> True) then
begin
WriteLn(ftp.LastErrorText);
Exit;
end;
bdA := TBinData.Create;
bdA.LoadFile('qa_data/jpg/penguins.jpg');
// Upload the contents of bdA to the FTP server.
remoteFilename := 'penguins.jpg';
success := ftp.PutFileBd(bdA,remoteFilename);
if (success <> True) then
begin
WriteLn(ftp.LastErrorText);
Exit;
end;
// Download...
bdB := TBinData.Create;
success := ftp.GetFileBd(remoteFilename,bdB);
if (success <> True) then
begin
WriteLn(ftp.LastErrorText);
Exit;
end;
// Verify that bdA and bdB have the exact same contents.
WriteLn('size of bdA: ' + bdA.NumBytes);
if (bdA.ContentsEqual(bdB) = True) then
begin
WriteLn('Contents are equal. Success.');
end
else
begin
WriteLn('Contents are NOT equal. Failed.');
end;
ftp.Disconnect();
ftp.Free;
bdA.Free;
bdB.Free;
end;
// ---------------------------------------------------------------------------
begin
try
RunDemo;
except
on E: Exception do
WriteLn('Unhandled exception: ', E.ClassName, ': ', E.Message);
end;
WriteLn;
{$IFDEF MSWINDOWS}
WriteLn('Press Enter to exit...');
ReadLn;
{$ENDIF}
end.