sftp/sample.dpr

// Technical support: support@smartftp.com

program sample;

{$APPTYPE CONSOLE}

uses
  System.SysUtils,
  ActiveX,
  // IMPORTANT: Import the SmartFTP FTP Library:
  // menu: Component - Import Component
  // Import a Type Library
  // SmartFTP FTP 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, the component reads the product key from the Windows registry.
  // The product key can be set using the supplied SetProductKey.cmd script from the installation folder.  
  // If no product key is found in the registry, e.g. during the trial period, 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: For manual activation, use the provided product key after purchasing 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.