sftp/Module1.vb
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 73 74 | ' Technical support: support@smartftp.com Module Module1 Dim sshConnection As sfFTPLib.SSHConnection Dim sftpConnection As sfFTPLib.SFTPConnection Sub SFTPTest() sftpConnection = sshConnection.CreateSFTPConnection() 'Dim fileLogger = sftpConnection.SetFileLogger() 'fileLogger.File = "sftp.log" sftpConnection.Connect() Dim currentDirectory = sftpConnection.RealPath( "." ) ' Read Directory Dim directoryItems As sfFTPLib.FTPItems = sftpConnection.ReadDirectory(currentDirectory) Dim item As sfFTPLib.FTPItem For Each item In directoryItems If item.Type = sfFTPLib.ItemType.ftpItemTypeRegularFile Then System.Console.WriteLine( "Type={0}; Name={1}; Size={2}" , item.Type, item.Name, item.Size) Else System.Console.WriteLine( "Type={0}; Name={1}" , item.Type, item.Name) End If Next ' Download File Dim startPosition As ULong = 0 Dim endPosition As ULong = ULong.MaxValue ' Note: The first argument is the full path to the source file sftpConnection.DownloadFileEx( "/History.txt" , "History.txt" , sfFTPLib.DataTransferType.ftpDataTransferTypeImage, startPosition, endPosition, sfFTPLib.DownloadFlags.ftpDownloadFlagReadBeyondEnd, Nothing ) System.Console.WriteLine( "DownloadFile() successful." ) System.Console.WriteLine( "LastTransferBytes = {0} B" , sftpConnection.LastTransferBytes) System.Console.WriteLine( "LastTransferTime = {0} s" , sftpConnection.LastTransferTime) System.Console.WriteLine( "LastTransferSpeed = {0} B/s" , sftpConnection.LastTransferSpeed) ' Upload file 'sftpConnection.UploadFileEx("c:\test.dat", "/remotefolder/test.dat", sfFTPLib.DataTransferType.ftpDataTransferTypeImage, startPosition, Nothing) End Sub Sub Main() Dim ftplibGlobal = New sfFTPLib.[Global] ' Load License ' 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 'ftplibGlobal.LoadLicense("XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX") sshConnection = New sfFTPLib.SSHConnection ' Favorite settings sshConnection.Host = "localhost" sshConnection.Port = 22 sshConnection.Username = "username" sshConnection.Password = "password" ' Proxy settings 'sshConnection.Proxy.Type = sfFTPLib.ProxyType.ftpProxyTypeNone 'Dim fileLogger As sfFTPLib.FileLogger 'fileLogger = sshConnection.SetFileLogger() 'fileLogger.File = "ssh.log" sshConnection.Connect() SFTPTest() sshConnection.Disconnect() sshConnection = Nothing End Sub End Module |