sftp/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 | // Technical support: support@smartftp.com program sample; {$APPTYPE CONSOLE} uses System . SysUtils, ActiveX, // Component - Import Component // Import a Type Library // SmartFTP FTP Type 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 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'); 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 . |