ftp/Module1.bas

Attribute VB_Name = "Module1"
' Technical support: support@smartftp.com

Option Explicit

Public ftpConnection As sfFTPLib.FTPConnectionSTA
Public objGlobal As sfFTPLib.Global

' With events
'Dim WithEvents ftpConnection As FTPConnectionSTA

Sub Main()
	' VB6 binding howto
	' https://kandkconsulting.tripod.com/VB/Tutorials/vb_binding_tutorial.htm


	'Early Binding "Dual Interface"
	'Note: Force the compiler to use the dual interface if available
	Set objGlobal = CreateObject("sfFTPLib.Global")

	' If LoadLicense Is not called, the component reads the product key from the Windows registry.
	' The product key can be set using the supplied SetProductKey.cmd script from the installation folder.
	' If no product key Is found in the registry, e.g. during the trial period, 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: For manual activation, use the provided product key after purchasing a license.
	'objGlobal.LoadLicense("XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX")

	'Early Binding "Dual Interface"
	'Note: Force the compiler to use the dual interface if available
	Set ftpConnection = CreateObject("sfFTPLib.FTPConnectionSTA")

    'Early Binding "Mid Level"
    'Note: The compiler may use the dual interface
    'Set ftpConnection = New sfFTPLib.FTPConnectionSTA
    
    ftpConnection.Host = "ftp.smartftp.com"
    'ftpConnection.Port = 21
    ftpConnection.Protocol = ftpProtocolPreferTLS
    ftpConnection.Username = "anonymous"
    ftpConnection.Password = "test@test.com"
    'ftpConnection.Passive = True
    
		'Dim fileLogger As sfFTPLib.FileLogger
		'Set fileLogger = ftpConnection.SetFileLogger()
		'fileLogger.File = "VB6Demo.log"

    Call ftpConnection.Connect
    MsgBox ("Connected.")
    ftpConnection.ChangeDirectory ("/")
    MsgBox ("ChangeDirectory() successful.")
    ' Read Directory
    Dim ftpItems As sfFTPLib.FTPItems
    Set ftpItems = ftpConnection.ReadDirectory()
    Dim ftpItem As sfFTPLib.FTPItem
    Dim strList
    For Each ftpItem In ftpItems
        strList = strList & "Type=" & ftpItem.Type & "; Name=" & ftpItem.Name & "; Size=" & ftpItem.SizeLo & Chr(13) & Chr(10)
    Next
    MsgBox (strList)

    ' Download File
    Dim nRestartLo: nRestartLo = 0
    Dim nRestartHi: nRestartHi = 0

    Dim strMsg
    Call ftpConnection.DownloadFile("This is a DEMO server.txt", "This is a DEMO server.txt", nRestartLo, nRestartHi)
    strMsg = "DownloadFile() successful." & Chr(13) & Chr(10)
    strMsg = strMsg & "LastTransferBytes = " & ftpConnection.LastTransferBytesLo & " B" & Chr(13) & Chr(10)
    strMsg = strMsg & "LastTransferTime = " & ftpConnection.LastTransferTime & " s" & Chr(13) & Chr(10)
    strMsg = strMsg & "LastTransferSpeed = " & ftpConnection.LastTransferSpeed & " B/s"
    MsgBox (strMsg)
End Sub