sftp/Module1.bas
Attribute VB_Name = "Module1"
Option Explicit
Public objFTP As sfFTPLib.SFTPConnection
Public objGlobal As sfFTPLib.Global
' With events
'Dim WithEvents objFTP As SFTPConnection
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")
Dim strKey As String
' New Version
strKey = strKey & "<?xml version=""1.0"" ?>" & Chr(13) & Chr(10)
strKey = strKey & "<License>" & Chr(13) & Chr(10)
strKey = strKey & "<Version>2.0</Version>" & Chr(13) & Chr(10)
strKey = strKey & "<Id>400012345</Id>" & Chr(13) & Chr(10)
strKey = strKey & "<Name>name</Name>" & Chr(13) & Chr(10)
strKey = strKey & "<Email>user@host.com</Email>" & Chr(13) & Chr(10)
strKey = strKey & "<Company>company</Company>" & Chr(13) & Chr(10)
strKey = strKey & "<Product>SmartFTP FTP Library</Product>" & Chr(13) & Chr(10)
strKey = strKey & "<Features>" & Chr(13) & Chr(10)
strKey = strKey & "<Feature>SFTP</Feature>" & Chr(13) & Chr(10)
strKey = strKey & "</Features>" & Chr(13) & Chr(10)
strKey = strKey & "<Users>1</Users>" & Chr(13) & Chr(10)
strKey = strKey & "<Maintenance>2008-12-27</Maintenance>" & Chr(13) & Chr(10)
strKey = strKey & "<Issue>2007-12-27</Issue>" & Chr(13) & Chr(10)
strKey = strKey & "<Signature>xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx</Signature>" & Chr(13) & Chr(10)
strKey = strKey & "</License>" & Chr(13) & Chr(10)
If objGlobal.LoadLicenseKeyData(strKey) 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.SFTPConnection")
'Early Binding "Mid Level"
'Note: The compiler may use the dual interface
'Set objFTP = New sfFTPLib.SFTPConnection
objFTP.Host = "yourhost"
objFTP.Port = 22
objFTP.Username = "anonymous"
objFTP.Password = "test@test.com"
objFTP.LogFile = "VB6Demo.log"
If objFTP.Connect = sfFTPLib.enumError.ftpErrorSuccess Then
MsgBox ("Connected.")
If objFTP.RealPath(".") = sfFTPLib.enumError.ftpErrorSuccess Then
MsgBox ("RealPath() successful.")
' Read Directory
If objFTP.ReadDirectory() = sfFTPLib.enumError.ftpErrorSuccess Then
MsgBox ("ReadDirectory() successful.")
Dim objDirectory As sfFTPLib.SFTPItems
Set objDirectory = objFTP.Items
Dim objItem As sfFTPLib.SFTPItem
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)
Else
MsgBox ("ReadDirectory() failed.")
End If
' Download File
Dim nRestartLo : nRestartLo = 0
Dim nRestartHi : nRestartHi = 0
Dim strMsg
If objFTP.DownloadFile("/path/file", "myfile", nRestartLo, nRestartHi, nRestartLo, nRestartHi) = sfFTPLib.enumError.ftpErrorSuccess Then
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)
Else
strMsg = "DownloadFile() failed." Chr(13) & Chr(10)
MsgBox (strMsg)
End If
Else
MsgBox ("ChangeDirectory() failed.")
End If
Else
MsgBox ("Connect() failed.")
End If
End Sub