ftp/Delphi2005forWindowsDemo.dpr

// Technical support: support@smartftp.com

program Delphi2005forWindowsDemo;

{$APPTYPE CONSOLE}

uses
  SysUtils,
  ActiveX,
  sfFTPLib_TLB in 'sfFTPLib_TLB.pas';

var
    objFTP : FTPConnectionMTA;
    objItem : FTPItem;
    objDirectory : FTPItems;
    i : Integer;

begin
  // initalize COM. Delphi doesn't do it for us?
  CoInitialize(nil);

  // Use default=dual interface
  objFTP := CoFTPConnectionMTA.Create();

  // FTP settings
  objFTP.Host := 'ftp.smartftp.com';
  objFTP.Username := 'anonymous';
  objFTP.Password := 'test@test.com';
  objFTP.Passive := true;
  objFTP.Protocol := ftpProtocolSSLExplicit;
  // log everything
  objFTP.LogFile.File := 'Delphi2005Demo.log';

  objFTP.Connect();
	WriteLn('Connected.');

  objFTP.ChangeDirectory('/SmartFTP');	
	objDirectory := objFTP.ReadDirectory();
	WriteLn('Directory Count = ', objDirectory.Count);
 	// Note: If you want to use the _NewEnum please see http://www.delphipraxis.net/post90962.html
  for i:=0 to objDirectory.Count - 1 do
  begin
  	objItem := objDirectory.Item[i];
    // Note: When importing the TLB, Delphi converts the "Type" to "type_"
    WriteLn('Type= ',objItem.type_, '; Name=', objItem.Name, '; Size=', objItem.Size);
    // manually destroy the item
    objItem := nil;
  end;
  // manually destroy the object
  objDirectory := nil;

	// Download File
  objFTP.DownloadFile('History.txt', 'History.txt', 0, 0);
  WriteLn('DownloadFile() successful.');
  WriteLn('LastTransferBytes = ', objFTP.LastTransferBytes, ' B');
  WriteLn('LastTransferTime = ', objFTP.LastTransferTime, ' s');
  WriteLn('LastTransferSpeed = ', objFTP.LastTransferSpeed, ' B/s');
 
  objFTP.Disconnect();
  objFTP := nil;
end.