In my last blog post I reviewed the SmartFTP Client, where I briefly mentioned that the SmartFTP Client has built-in extensibility support, and I promised to include a script that I’ve been testing. I have made it abundantly obvious in many of my earlier blog posts that I love writing scripts or extending the functionality of existing products whenever I can, so having built-in extensibility for an FTP client definitely caught my interest.
To begin with, you can download the SDK for the SmartFTP Client from the following URL:
The SDK will give you a couple of CHM files that contain the documentation for the SmartFTP Client extensibility features and a handful of samples to get you started. After I downloaded the SDK I spent some time looking at the documentation and a few of the existing samples, and I was able to create a simple FTP client pretty easily based on what I had seen.
So without further discussion, here is the annotated sample that I have been testing:
‘ Bypass any errors.
On Error Resume Next
‘ Declare the object variables.
‘ Define some constants.
‘ Note: These are from the CHM file in the SDK.
Const ftpProtocolNormal = 0
Const ftpErrorSuccess = 0
‘ Try to retrieve an exsting object for the SmartFTP client.
Set objSmartFTP = GetObject(“SmartFTP.Application”)
‘ Test if we were able to get an exsting object.
If TypeName(objSmartFTP) <> “Application” Then
‘ Instantiate a new instance if no client is present.
Set objSmartFTP = WScript.CreateObject(“SmartFTP.Application”)
‘ Hide the SmartFTP client.
objSmartFTP.Visible = False
‘ Create a connection object.
Set objFTPConnection = objSmartFTP.CreateObject(“sfFTPLib.FTPConnectionSTA”)
‘ Specify the connection properties.
objFTPConnection.Host = “ftp.example.com”
objFTPConnection.SendHOST = True
objFTPConnection.Username = “foo”
objFTPConnection.Password = “bar”
objFTPConnection.Port = 21
objFTPConnection.Protocol = ftpProtocolNormal
objFTPConnection.Passive = True
objFTPConnection.MLST = True
‘ Connect to the FTP site and test for success.
If objFTPConnection.Connect = ftpErrorSuccess Then
‘ Display the FTP server’s welcome message.
‘ Download the IIS start page to a local TEMP folder.
“C:\temp\iisstart.htm”, 0, 0) = ftpErrorSuccess Then
WScript.Echo “Download successful.”
WScript.Echo “Download failed. Error = “ & objFTPConnection.LastError
WScript.Echo “Connection failed. Error = “ & objFTPConnection.LastError
‘ Destroy the connection object.
Set objFTPConnection = Nothing
‘ Close the SmartFTP client.
‘ Destroy the SmartFTP object.
Set objSmartFTP = Nothing
I should mention again that I am using the SmartFTP Client Ultimate Edition version 4.0.1105.0, just in case something is different in an earlier or later build. ;-]