How to Easily Use FTP in WSH
(Page 1 of 4 )
In my last article I showed you a work around that allowed you to use FTP in WSH. This time I’m going to show you a much easier, more flexible approach using a third-party ActiveX control designed to expand WSH.
ActiveX controls can be used to add functionality to WSH that it does not have natively. The ActiveX must be written for this purpose and must provide a COM interface. Once the ActiveX control is instantiated in your script, you will be able to access all of the methods and properties that it provides.
ActiveX controls must be installed on the system on which they are being used. Simply referencing a file is not enough. To install an ActiveX control, it must be registered, meaning that a set of registry keys must be created that reference it as a COM object. Many third parties will include installers for this.
If your ActiveX control does not have an installer, you can register it yourself from the command line. Navigate to the directory where your control is located and use the command regsvr32 activex.ocx with the name of your control.
We’ll be using Chilkat’s Free FTP ActiveX control. This ActiveX control acts as a sort of scriptable FTP client that provides access to the most common FTP functions. There are two versions—one free and one commercial. While we’ll be using the free control for this demonstration, the paid version offers some very cool functionality.
Once you’ve installed the control, you’ll be able to access it through its COM interface by connecting to the ChilkatFTP.ChilkatFTP namespace.
Set objFtp = CreateObject("ChilkatFTP.ChilkatFTP")
Next you’ll want to make a connection. To do that you’ll need to provide the hostname, username, and password. The FTP control provides properties for this.
objFtp.Hostname = "ftp.mysite.com"
objFtp.Username = USERNAME
objFtp.Password = PASSWORD
success = objFtp.Connect()
Finally, the Connect method makes the connection. Be sure to catch the return code for error handling purposes.
If (success <> 1) Then
Wscript.Echo objFtp.LastErrorText
Wscript.Quit
End If
Next: Uploading and Downloading files >>
More Windows Scripting Articles
More By Nilpo