Delphi DLL
Delphi DLL
Quote and SendCommand
See more FTP Examples
Demonstrate the Quote and SendCommand methods.Chilkat Delphi DLL Downloads
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Ftp2;
...
procedure TForm1.Button1Click(Sender: TObject);
var
success: Boolean;
ftp: HCkFtp2;
serverResponse: PWideChar;
begin
success := False;
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
ftp := CkFtp2_Create();
CkFtp2_putHostname(ftp,'ftp.example.com');
CkFtp2_putUsername(ftp,'login');
CkFtp2_putPassword(ftp,'password');
// Connect and login to the FTP server.
success := CkFtp2_Connect(ftp);
if (success <> True) then
begin
Memo1.Lines.Add(CkFtp2__lastErrorText(ftp));
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.
CkFtp2_putKeepSessionLog(ftp,True);
// Change the current remote directory via the Quote method:
success := CkFtp2_Quote(ftp,'CWD junk');
if (success <> True) then
begin
Memo1.Lines.Add(CkFtp2__lastErrorText(ftp));
Exit;
end;
// Move back up
// In this case, ChangeRemoteDir sends "CWD .." to the FTP server.
success := CkFtp2_ChangeRemoteDir(ftp,'..');
if (success <> True) then
begin
Memo1.Lines.Add(CkFtp2__lastErrorText(ftp));
Exit;
end;
// Do the same via the SendCommand method where the
// raw FTP server response is returned:
serverResponse := CkFtp2__sendCommand(ftp,'CWD junk');
if (CkFtp2_getLastMethodSuccess(ftp) <> True) then
begin
Memo1.Lines.Add(CkFtp2__lastErrorText(ftp));
end
else
begin
Memo1.Lines.Add(serverResponse);
end;
success := CkFtp2_Disconnect(ftp);
Memo1.Lines.Add('Session Log:');
Memo1.Lines.Add(CkFtp2__sessionLog(ftp));
CkFtp2_Dispose(ftp);
end;