sftp/sample.dpr

// Technical support: support@smartftp.com

program sample;

{$APPTYPE CONSOLE}

uses
  System.SysUtils,
  ActiveX,
  // Component - Import Component
  // Import a Type Library
  // SmartFTP FTP Type Library 4.0
  sfFTPLib_TLB in 'sfFTPLib_TLB.pas';

var
  connection : ISSHConnection;
  sftp : ISFTPConnection;
  fileLogger : IFileLogger;
  sftpFileLogger : IFileLogger;
  global : IGlobal;
  homeDirectory : String;
  item : IFTPItem;
  items : IFTPItems;
  i : Integer;

begin
  CoInitialize(nil);

  global := CoGlobal.Create();

  // If LoadLicense is not called a trial license is automatically obtained from the activation server. The FTP Library uses WinHTTP to access
  // the activation server at www.smartftp.com (TLS, port 443). Ensure that your application is not blocked by any firewall.
  // TODO: insert the provided serial after the purchase of a license
  //global.LoadLicense('XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX');

  connection := CoSSHConnection.Create();

  connection.Host := 'localhost';
  connection.Port := 22;
  connection.Username := 'anonymous';
  connection.Password := 'test@test.com';

  // log everything
  fileLogger := connection.SetFileLogger();
  fileLogger.file_ := 'ssh.log';

  connection.Connect();
  Writeln('Connected.');

  sftp := connection.CreateSFTPConnection();
  sftpFileLogger := sftp.SetFileLogger();
  sftpFileLogger.file_ := 'sftp.log';

  sftp.Connect();

  homeDirectory := sftp.RealPath('.');
  Writeln('Home Directory: ' + homeDirectory);

  items := sftp.ReadDirectory(homeDirectory);

  for i:=0 to items.Count - 1 do
  begin
    item := items.Item[i];
    Writeln(item.Name);
    item := nil;
  end;
  items := nil;

  connection.Disconnect();
  connection := nil;
end.