Quicklinks
ActiveSocket provides an easy-to-use development interface to a variety of IP protocols. By using ActiveSocket, you can very easily create or enhance applications with network features.
ActiveSocket features the following: DNS, FTP, HTTP, HTTPs, ICMP Ping, IP-to-Country, MSN, NTP, RSH, SCP, SFTP, SNMP v1/v2c (Get, GetNext, Set), SNMP Traps, SNMP MIB, SSH, TCP, Telnet, TFTP, UDP, Telnet, Wake-On-LAN and more.
ActiveSocket can be well integrated into ASP environments. This document describes how the ActiveSocket SFtp object can be integrated into VBScript projects.
The most important functions of the SFtp object are:
Download ActiveSocket from the ActiveXperts Download Site and start the installation. The installation guides you through the installation process.
Create a new script using your favorite editor. You can simply use notepad. However, a VBScript editor is recommended, so you can browse through objects, objects properties and object functions.
You're now able to write a more advanced script to communicate using the ActiveSocket Toolkit.
Option Explicit
This statement requires that all variable names be defined (with the Dim statement), to avoid simple typos that can cause incredible headaches and long debugging sessions for something that should have never happened.
Now, declare the ActiveSocket object(s):
Dim objSFtp
Create the ActiveSocket object(s) like this:
Set objSFtp = CreateObject( "ActiveXperts.SFtp" )
Now, add the following lines to the file to have your fist ActiveSocket VBScript program:
WScript.Echo "Version: " & objSFtp.Version WScript.Echo "Expiration Date: " & objSFtp.Expiration Date
You can now connect to a remote FTP server, logon, change directory and perform file operations.
The following VBScript code shows how to list files in a specific directory on a remote FTP server:
' Helper function to expand a string variable to a specified length Function Pad(ByRef Text, ByVal Length) Pad = Left(Text & Space(Length), Length) End Function ' Helper function to test and find the error description and exit Function test_lasterror() If objSFtp.LastError <> 0 Then WScript.Echo "Error " & objSFtp.LastError If objSFtp.ProtocolError <> "" Then WScript.Echo "Protocol error: " & objSFtp.ProtocolError WScript.Quit 1 End If End If End Function ' Connect to the host Set objSFtp = CreateObject("ActiveXperts.SFtp") ' Create an SFtp instance objSFtp.Host = "192.168.1.10" ' Hostname or IP address of remote UNIX/LINUX machine objSFtp.UserName = "demo" ' Login as 'demo' objSFtp.Password = "topsecret" ' Use a password to login WScript.Echo "Connect" objSFtp.Connect ' Connect to the SFTP server test_lasterror ' Change directory objSFtp.ChangeDir "test" test_lasterror ' List directory contents Set f = objSFtp.FindFirstFile(".") test_lasterror While objSFtp.LastError = 0 str = pad(f.name, 30) & pad(f.SizeKb & "KB", 10) & f.Date WScript.Echo str Set f = objSFtp.FindNextFile WEnd ' Get smalltoken file objSFtp.GetFile "Smalltoken.file", "." test_lasterror objSFtp.Disconnect ' YES, command has completed WScript.Echo "Ready."
There are many working samples included with the product. You can also find them on the ActiveXperts FTP site: ftp.activexperts-labs.com/samples/network-component.