ftp/Module1.vb

' Technical support: support@smartftp.com

Option Explicit On 

Module Module1

    Dim objFTP As sfFTPLib.FTPConnectionMTAClass

    Sub Main()
        Dim objGlobal As sfFTPLib.[Global]
        'objGlobal = CreateObject("sfFTPLib.Global")
        objGlobal = New sfFTPLib.[Global]
		
        ' Load License Key
        ' Uncomment to load license
        'objGlobal.LoadLicense("XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX")

        'Dim objUPnP As sfFTPLib.UPnPNATManager
        'objUPnP = New sfFTPLib.UPnPNATManager
        'Try
        '	objUPnP.Initialize()
				'Catch ex As Exception
        '    System.Console.WriteLine("No UPnP router/device found.")					
				'End Try

        'objFTP = CreateObject("sfFTPLib.FTPConnectionMTA")
        objFTP = New sfFTPLib.FTPConnectionMTA

        ' Attach the event handler
        AddHandler objFTP.OnConnect, AddressOf OnConnect
        AddHandler objFTP.OnTransferProgress, AddressOf OnTransferProgress

        ' Favorite settings
        objFTP.Host = "ftp.smartftp.com"
        objFTP.Port = 21
        objFTP.Protocol = sfFTPLib.enumProtocol.ftpProtocolSSLExplicit
        objFTP.Username = "anonymous"
        objFTP.Password = "test@test.com"
        objFTP.MLST = True
        objFTP.Passive = True

        ' Proxy settings
        'objFTP.Proxy.Type = sfFTPLib.enumProxyType.ftpProxyTypeNone
        'objFTP.FTPProxy.Type = sfFTPLib.enumFTPProxyType.ftpFTPProxyTypeNone

        objFTP.LogFile.File = "VBDemo.log"

        objFTP.Connect()
        objFTP.ChangeDirectory("/SmartFTP")
        
        Dim objDirectory As sfFTPLib.FTPItemsClass
        objDirectory = objFTP.ReadDirectory()
        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 nRestartLo As System.UInt32
        Dim nRestartHi As System.UInt32
        ' Convert value to UInt32
        nRestartLo = System.Convert.ToUInt32(0)
        nRestartHi = System.Convert.ToUInt32(0)

        objFTP.DownloadFile("History.txt", "History.txt", nRestartLo, nRestartHi)
        System.Console.WriteLine("DownloadFile() successful.")
				System.Console.WriteLine("LastTransferBytes = {0} B", objFTP.LastTransferBytes)
        System.Console.WriteLine("LastTransferTime = {0} s", objFTP.LastTransferTime)
        System.Console.WriteLine("LastTransferSpeed = {0} B/s", objFTP.LastTransferSpeed)

        objFTP.Disconnect()

        'objUPnP.Uninitialize()
        objFTP = Nothing
        
    End Sub

    Sub OnConnect()
        System.Console.WriteLine("OnConnect()")
    End Sub

    Sub OnTransferProgress(ByVal nLo As System.Int32, ByVal nHi As System.Int32)
        System.Console.WriteLine("OnTransferProgress(""{0}"")", objFTP.LastTransferBytes)
    End Sub

End Module