ftp/sample.dpr
// Technical support: support@smartftp.com
program sample;
{$APPTYPE CONSOLE}
uses
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
ftpConnection : FTPConnectionMTA;
ftpItem : FTPItem;
ftpDirectory : FTPItems;
i : Integer;
fileLogger : IFileLogger;
global : IGlobal;
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');
// Use default=dual interface
ftpConnection := CoFTPConnectionMTA.Create();
// FTP settings
ftpConnection.Host := 'ftp.smartftp.com';
ftpConnection.Username := 'anonymous';
ftpConnection.Password := 'test@test.com';
//ftpConnection.Passive := true;
ftpConnection.Protocol := ftpProtocolPreferTLS;
// log everything
//fileLogger := ftpConnection.SetFileLogger();
//fileLogger.file_ := 'Delphi2005Demo.log';
ftpConnection.Connect();
WriteLn('Connected.');
ftpConnection.ChangeDirectory('/');
ftpDirectory := ftpConnection.ReadDirectory();
WriteLn('Directory Count = ', ftpDirectory.Count);
// Note: If you want to use the _NewEnum please see http://www.delphipraxis.net/post90962.html
for i:=0 to ftpDirectory.Count - 1 do
begin
ftpItem := ftpDirectory.Item[i];
// Note: When importing the TLB, Delphi converts the "Type" to "type_"
WriteLn('Type= ',ftpItem.type_, '; Name=', ftpItem.Name, '; Size=', ftpItem.Size);
ftpItem := nil;
end;
ftpDirectory := nil;
// Download File
ftpConnection.DownloadFile('This is a DEMO server.txt', 'This is a DEMO server.txt', 0, 0);
WriteLn('DownloadFile() successful.');
WriteLn('LastTransferBytes = ', ftpConnection.LastTransferBytes, ' B');
WriteLn('LastTransferTime = ', ftpConnection.LastTransferTime, ' s');
WriteLn('LastTransferSpeed = ', ftpConnection.LastTransferSpeed, ' B/s');
ftpConnection.Disconnect();
ftpConnection := nil;
end.