ftp/Module1.bas

Attribute VB_Name = "Module1"
Option Explicit

Public objFTP As sfFTPLib.FTPConnectionSTA
Public objGlobal As sfFTPLib.Global

' With events
'Dim WithEvents objFTP As FTPConnectionSTA

Sub Main()
    ' VB6 binding howto
   ' http://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 objGlobal.LoadLicenseKeyData("...") Then
            MsgBox ("License key verified.")
      Else
            MsgBox ("Failed to verify license key.")       
      End If

    'Early Binding "Dual Interface"
   'Note: Force the compiler to use the dual interface if available
   Set objFTP = CreateObject("sfFTPLib.FTPConnectionSTA")
   
    'Early Binding "Mid Level"
   'Note: The compiler may use the dual interface
   'Set objFTP = New sfFTPLib.FTPConnectionSTA
   
    objFTP.Host = "ftp.smartftp.com"
    objFTP.Port = 21
    objFTP.Protocol = ftpProtocolSSLExplicit
    objFTP.Username = "anonymous"
    objFTP.Password = "test@test.com"
    objFTP.Passive = True
    objFTP.LogFile = "VB6Demo.log"
   
    If objFTP.Connect = sfFTPLib.enumError.ftpErrorSuccess Then
        MsgBox ("Connected.")
        If objFTP.ChangeDirectory("/SmartFTP") = sfFTPLib.enumError.ftpErrorSuccess Then
            MsgBox ("ChangeDirectory() successful.")
            ' Read Directory
           If objFTP.ReadDirectory() = sfFTPLib.enumError.ftpErrorSuccess Then
                MsgBox ("ReadDirectory() successful.")
                Dim objDirectory As sfFTPLib.FTPDirectory
                Set objDirectory = objFTP.Directory
                Dim objItem As sfFTPLib.FTPItem
                Dim strList
                For Each objItem In objDirectory
                    strList = strList & "Type=" & objItem.Type & "; Name=" & objItem.Name & "; Size=" & objItem.SizeLo & vbCrLf
                Next
                MsgBox (strList)
            Else
                MsgBox ("ReadDirectory() failed. LastError = " & objFTP.LastError)
            End If

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

            Dim strMsg
            If objFTP.DownloadFile("History.txt", "History.txt", nRestartLo, nRestartHi) = sfFTPLib.enumError.ftpErrorSuccess Then
                strMsg = "DownloadFile() successful." & vbCrLf
                strMsg = strMsg & "LastTransferBytes = " & objFTP.LastTransferBytesLo & " B" & vbCrLf
                strMsg = strMsg & "LastTransferTime = " & objFTP.LastTransferTime & " s" & vbCrLf
                strMsg = strMsg & "LastTransferSpeed = " & objFTP.LastTransferSpeed & " B/s"
                MsgBox (strMsg)
            Else

                strMsg = "DownloadFile() failed. LastError = " & objFTP.LastError & vbCrLf
                strMsg = strMsg & "LastReplyCode = " & objFTP.LastReplyCode & vbCrLf
                strMsg = strMsg & "LastReply = " & objFTP.LastReply & vbCrLf
                MsgBox (strMsg)
            End If
        Else
            MsgBox ("ChangeDirectory() failed. LastError = " & objFTP.LastError)
        End If
       
    Else
        MsgBox ("Connect() failed. LastError = " & objFTP.LastError)
    End If
End Sub

 
© SmartSoft Ltd.