sftp/Module1.vb

' Technical support: support@smartftp.com

Module Module1

    Dim objSSH As sfFTPLib.SSHConnectionClass
    Dim objSFTP As sfFTPLib.SFTPConnectionClass

    Sub SFTPTest()
        objSFTP = objSSH.CreateSFTPConnection()
        objSFTP.Connect()

        Dim strCurrentDirectory As System.String
        strCurrentDirectory = objSFTP.RealPath(".")

        ' Read Directory        
        Dim objDirectory As sfFTPLib.FTPItemsClass
        objDirectory = objSFTP.ReadDirectory(strCurrentDirectory)
        Dim objItem As sfFTPLib.FTPItem
        For Each objItem In objDirectory
            System.Console.WriteLine("Type={0}; Name={1}; Size={2}", objItem.Type, objItem.Name, objItem.Size)
        Next

        ' Download File
        Dim startPosition As System.UInt64
        startPosition = 0
        Dim endPosition As System.UInt64
        endPosition = 0

        ' Note: The first argument is the full path to the source file
        objSFTP.DownloadFileEx("History.txt", "History.txt", startPosition, endPosition)
        System.Console.WriteLine("DownloadFile() successful.")
        System.Console.WriteLine("LastTransferBytes = {0} B", objSFTP.LastTransferBytes)
        System.Console.WriteLine("LastTransferTime = {0} s", objSFTP.LastTransferTime)
        System.Console.WriteLine("LastTransferSpeed = {0} B/s", objSFTP.LastTransferSpeed)

    End Sub

    Sub Main()
        Dim objGlobal As sfFTPLib.[Global]
        'objGlobal = CreateObject("sfFTPLib.Global")
        objGlobal = New sfFTPLib.[Global]

        ' Load License
        'objGlobal.LoadLicense("XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX")

        'objFTP = CreateObject("sfFTPLib.SSHConnection")
        objSSH = New sfFTPLib.SSHConnection

        ' Favorite settings
        objSSH.Host = "localhost"
        objSSH.Port = 22
        objSSH.Username = "username"
        objSSH.Password = "password"

        ' Proxy settings
        objSSH.Proxy.Type = sfFTPLib.enumProxyType.ftpProxyTypeNone

        objSSH.LogFile.File = "VBDemo.log"

        objSSH.Connect()
        SFTPTest()
        objSSH.Disconnect()

        'objUPnP.Uninitialize()
        objSSH = Nothing
    End Sub
End Module