ftp/sample.dpr
// Technical support: support@smartftp.com
program sample;
{$APPTYPE CONSOLE}
uses
SysUtils,
ActiveX,
// IMPORTANT: Import the SmartFTP FTP Type Library:
// menu: Component - Import Component
// Import a Type Library
// SmartFTP FTP Type Library 4.0
sfFTPLib_TLB in 'sfFTPLib_TLB.pas';
var
objFTP : FTPConnectionMTA;
objItem : FTPItem;
objDirectory : FTPItems;
i : Integer;
fileLogger : IFileLogger;
global : IGlobal;
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');
// 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
//fileLogger := objFTP.SetFileLogger();
//fileLogger.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);
objItem := nil;
end;
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.