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")
' If LoadLicense Is not called, the component reads the product key from the Windows registry.
' The product key can be set using the supplied SetProductKey.cmd script from the installation folder.
' If no product key Is found in the registry, e.g. during the trial period, a trial license Is automatically obtained
' from the activation server.
'
' The FTP Library uses WinHTTP to access the activation server at www.smartftp.com (TLS, port 443).
' Ensure that your application Is Not blocked by any firewall.
'
' TODO: For manual activation, use the provided product key after purchasing a license.
'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