sftp/Module1.bas

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

Option Explicit

Public objSSH As sfFTPLib.SSHConnection
Public objSFTP As sfFTPLib.SFTPConnection
Public objGlobal As sfFTPLib.Global

' With events
'Dim WithEvents objSFTP As SFTPConnection

Sub SFTPTest()
    Set objSFTP = objSSH.CreateSFTPConnection()
    objSFTP.LogFile.File = "sftp.log"
    Call objSFTP.Connect
    Dim strHome
    strHome = objSFTP.RealPath(".")
    MsgBox ("RealPath() successful.")
    ' Read Directory
    Dim objItems As sfFTPLib.FTPItems
    Set objItems = objSFTP.ReadDirectory(strHome)
    Dim objItem As sfFTPLib.FTPItem
    Dim strList
    For Each objItem In objItems
        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 objSFTP.DownloadFile("/path/file", "myfile", nRestartLo, nRestartHi)
    strMsg = "DownloadFile() successful." & Chr(13) & Chr(10)
    strMsg = strMsg & "LastTransferBytes = " & objSFTP.LastTransferBytesLo & " B" & Chr(13) & Chr(10)
    strMsg = strMsg & "LastTransferTime = " & objSFTP.LastTransferTime & " s" & Chr(13) & Chr(10)
    strMsg = strMsg & "LastTransferSpeed = " & objSFTP.LastTransferSpeed & " B/s"
    MsgBox (strMsg)
End Sub

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")

    ' TODO: Uncomment the line and insert the provided serial after the purchase of the license.
    ' A trial license is automatically obtained from the license server. In this case do NOT uncomment the line.
    'objGlobal.LoadLicense ("XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX")

    'Early Binding "Dual Interface"
    'Note: Force the compiler to use the dual interface if available
    Set objSSH = CreateObject("sfFTPLib.SSHConnection")
    
    'Early Binding "Mid Level"
    'Note: The compiler may use the dual interface
    'Set objSSH = New sfFTPLib.SSHConnection
    
    objSSH.Host = "yourhost"
    objSSH.Port = 22
    objSSH.Username = "anonymous"
    objSSH.Password = "test@test.com"
    objSSH.LogFile.File = "ssh.log"
    
    Call objSSH.Connect
    MsgBox ("Connected.")
    Call SFTPTest
    Call objSSH.Disconnect
End Sub