ftp/sample.dpr
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 | // 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 . |