Pascal (Lazarus/Delphi)
Pascal (Lazarus/Delphi)
Quote and SendCommand
See more FTP Examples
Demonstrate the Quote and SendCommand methods.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;
// ---------------------------------------------------------------------------
procedure RunDemo;
var
success: Boolean;
ftp: TFtp2;
serverResponse: string;
begin
success := False;
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
ftp := TFtp2.Create;
ftp.Hostname := 'ftp.example.com';
ftp.Username := 'login';
ftp.Password := 'password';
// Connect and login to the FTP server.
success := ftp.Connect();
if (success <> True) then
begin
WriteLn(ftp.LastErrorText);
Exit;
end;
// Tell the FTP object to keep an in-memory session log
// so we can see the commands sent to the server,
// and the responses received back.
ftp.KeepSessionLog := True;
// Change the current remote directory via the Quote method:
success := ftp.Quote('CWD junk');
if (success <> True) then
begin
WriteLn(ftp.LastErrorText);
Exit;
end;
// Move back up
// In this case, ChangeRemoteDir sends "CWD .." to the FTP server.
success := ftp.ChangeRemoteDir('..');
if (success <> True) then
begin
WriteLn(ftp.LastErrorText);
Exit;
end;
// Do the same via the SendCommand method where the
// raw FTP server response is returned:
serverResponse := ftp.SendCommand('CWD junk');
if (ftp.LastMethodSuccess <> True) then
begin
WriteLn(ftp.LastErrorText);
end
else
begin
WriteLn(serverResponse);
end;
success := ftp.Disconnect();
WriteLn('Session Log:');
WriteLn(ftp.SessionLog);
ftp.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.