Sample code for 30+ languages & platforms
Delphi DLL

Check FTP Connection and Login Status

See more FTP Examples

Demonstrates the connection-status properties ConnectVerified, LoginVerified, ConnectFailReason, and Greeting.

Background: When Connect fails, these properties separate the possible causes: ConnectVerified shows whether the TCP connection was established at all, LoginVerified whether authentication then succeeded, and ConnectFailReason gives a numeric code pinpointing the failure — far more actionable than a generic error for distinguishing, say, an unreachable host from a bad password. The Greeting captures the server's opening banner, sometimes useful for identifying the server or its policies.

Chilkat Delphi DLL Downloads

Delphi DLL
var
success: Boolean;
ftp: HCkFtp2;

begin
success := False;

ftp := CkFtp2_Create();

CkFtp2_putHostname(ftp,'ftp.example.com');
CkFtp2_putUsername(ftp,'myFtpLogin');

//  Normally you would not hard-code the password in source.  You should instead obtain it
//  from an interactive prompt, environment variable, or a secrets vault.
CkFtp2_putPassword(ftp,'myPassword');

success := CkFtp2_Connect(ftp);
if (success <> True) then
  begin
    //  ConnectFailReason gives a numeric code describing why Connect failed.
    Memo1.Lines.Add('Connect failed, reason code: ' + IntToStr(CkFtp2_getConnectFailReason(ftp)));
    Memo1.Lines.Add(CkFtp2__lastErrorText(ftp));
    Exit;
  end;

//  After a successful connect, these flags report what succeeded.
Memo1.Lines.Add('TCP connection verified: ' + IntToStr(Ord(CkFtp2_getConnectVerified(ftp))));
Memo1.Lines.Add('Login verified: ' + IntToStr(Ord(CkFtp2_getLoginVerified(ftp))));

//  The Greeting property holds the server's initial greeting banner.
Memo1.Lines.Add('Server greeting: ' + CkFtp2__greeting(ftp));

success := CkFtp2_Disconnect(ftp);
if (success = False) then
  begin
    Memo1.Lines.Add(CkFtp2__lastErrorText(ftp));
    Exit;
  end;

CkFtp2_Dispose(ftp);