ftp/Module1.bas

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
Attribute VB_Name = "Module1"
' Technical support: support@smartftp.com
 
Option Explicit
 
Public objFTP As sfFTPLib.FTPConnectionSTA
Public objGlobal As sfFTPLib.Global
 
' With events
'Dim WithEvents objFTP As FTPConnectionSTA
 
Sub Main()
    ' VB6 binding howto
 
    'Early Binding "Dual Interface"
    'Note: Force the compiler to use the dual interface if available
    Set objGlobal = CreateObject("sfFTPLib.Global")
 
    ' Uncomment to load key from string
    'objGlobal.LoadLicense("XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX")
 
    '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 = ftpProtocolPreferTLS
    objFTP.Username = "anonymous"
    objFTP.Password = "test@test.com"
    objFTP.Passive = True
     
        'Dim fileLogger As sfFTPLib.FileLogger
        'Set fileLogger = objFTP.SetFileLogger()
        'fileLogger.File = "VB6Demo.log"
 
    Call objFTP.Connect
    MsgBox ("Connected.")
    objFTP.ChangeDirectory ("/SmartFTP")
    MsgBox ("ChangeDirectory() successful.")
    ' Read Directory
    Dim objDirectory As sfFTPLib.FTPItems
    Set objDirectory = objFTP.ReadDirectory()
    Dim objItem As sfFTPLib.FTPItem
    Dim strList
    For Each objItem In objDirectory
        strList = strList & "Type=" & objItem.Type & "; Name=" & objItem.Name & "; Size=" & objItem.SizeLo & Chr(13) & Chr(10)
    Next
    MsgBox (strList)
 
    ' Download File
    Dim nRestartLo: nRestartLo = 0
    Dim nRestartHi: nRestartHi = 0
 
    Dim strMsg
    Call objFTP.DownloadFile("History.txt", "History.txt", nRestartLo, nRestartHi)
    strMsg = "DownloadFile() successful." & Chr(13) & Chr(10)
    strMsg = strMsg & "LastTransferBytes = " & objFTP.LastTransferBytesLo & " B" & Chr(13) & Chr(10)
    strMsg = strMsg & "LastTransferTime = " & objFTP.LastTransferTime & " s" & Chr(13) & Chr(10)
    strMsg = strMsg & "LastTransferSpeed = " & objFTP.LastTransferSpeed & " B/s"
    MsgBox (strMsg)
End Sub