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

		Dim fileLogger As sfFTPLib.FileLogger
		Set fileLogger = objSFTP.SetFileLogger()
		fileLogger.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
        If objItem.Type = sfFTPLib.ftpItemTypeRegularFile Then
            strList = strList & "; Size=" & objItem.SizeLo 
        End If
        strList = strList & Chr(13) & Chr(10)
    Next
        MsgBox (strList)
 
    ' Download File
    Dim restartLo: restartLo = 0
    Dim restartHi: restartHi = 0

    Dim strMsg
    Call objSFTP.DownloadFile("/path/file", "c:\localfilepath", sfFTPLib.ftpDataTransferTypeImage, restartLo, restartHi)
    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"
		'Dim fileLogger As sfFTPLib.FileLogger
		'Set fileLogger = objSSH.SetFileLogger()
		'fileLogger.File = "ssh.log"
    
    Call objSSH.Connect
    MsgBox ("Connected.")
    Call SFTPTest
    Call objSSH.Disconnect
End Sub