ActiveSocket Manual

© 1999-2011 ActiveXperts Software B.V.  contact@activexperts.com

 

1. Introduction

1.1. What is ActiveSocket?

Adding network communications capabilities to an application is not a simple matter. It requires specialized knowledge that might be outside an individual programmer's expertise. For years, VBScript, Visual Basic and Visual C++ developers have relied upon the power, flexibility and reliability of the ActiveSocket Network Communication Toolkit from ActiveXperts Software. And today, also .NET developers use this control.

With ActiveSocket you can communicate across IP networks, including the Internet. ActiveSocket provides an easy-to-use scripting interface for IP communications. By using ActiveSocket, you can very easily create or enhance applications with network features.

Use ActiveSocket to integrate the following IP protocols in your application or script:

  • Dns - Query servers running a domain name service (DNS) application. Query DNS for specific information about hosts, like mail exchanger records [MX], IP address [A], canonical names [CNAME], etc.;
  • Ftp - Log on to an FTP server, change directory, list files, upload files (ftp/put), download files(ftp/get), create directories, delete directories, rename files, delete files, etc.;
  • Http/Https - Log on to a web server, get the web pages and analyze the contents. Support for Proxy servers, SSL and password protected web sites;
  • ICMP - See if you can reach another computer; Determine how long it takes to bounce a packet off of another site, which tells you its distance in network terms;
  • IP to Country - Translate an IP address to the associated country;
  • Msn - send an MSN message to one or more remote MSN recipients;
  • NTP - Query NTP time servers and retrieve the actual date and time. Calculate offset between servers to see if your LAN time is set properly;
  • RSH - Run a Shell Script on a remote UNIX or LINUX computer that runs the RSH (Remote Shell Script) daemon. Read StdErr and StdOut of the remote shell script;
  • SNMP - Query SNMP compliant devices and analyze the result. Set a value on a remote SNMP agent. Send SNMP traps to remote SNMP Managers, and receive incoming SNMP traps. Support for SNMP v1 and SNMP v2; Use the SNMP Browser to browse through an SNMP MIB file;
  • SNMP Traps - Send and receive SNMP traps to (remote) SNMP agents. Support for SNMP v1 and SNMP v2c;
  • SNMP MIB Browser - Load a MIB database into memory and iterate over all objects and view all properties;
  • SSH - Login onto a remote machine running the SSH daemon, and execute a command or shell script in a secure way;
  • TCP/IP client/server communications - Create your own client/server applications; your server-application listens for an incoming connection on a specific port, while your client application makes a connection to it; Client and server can communication bidirectional, with support for ASCII and binary data, in your LAN or through the internet;
  • Telnet - Automate Telnet sessions. Use the Telnet object to logon to a switch or router and make changes to the configuration. Log on to a mail server and list all items. Access a print server through telnet and reboot it. There are many devices and services that can be accessed by this Telnet object;
  • Tftp - Trivial FTP protocol with limited functionality. It uses UDP to upload files (put) and download files(get);
  • UDP communications - UDP-based client/server (peer-to-peer) communications and UDP broadcasts.
  • Wake-On-LAN (WOL); Wake up machines on your LAN, based on their MAC address;

ActiveSocket can be used by any of the following operating systems:

  • Windows 2008 (32-bit and 64-bit)
  • Windows 2003 (32-bit and 64-bit)
  • Windows 2000 (32-bit)
  • Windows 7 (32-bit and 64-bit)
  • Windows Vista (32-bit and 64-bit)
  • Windows XP (32-bit and 64-bit)

ActiveSocket Toolkit can be used by any of the following development languages:

  • Visual Basic .NET - Windows .NET based application
  • Visual C# .NET - Windows .NET based applications
  • Visual Basic 5.x or higher - Windows based applications
  • Visual C++ 5.x or higher - Windows based applications
  • Deplhi 7.x or higher - Windows based applications
  • ASP .NET - Web site based on Active Server Pages and the .NET Framework
  • ASP 2.x - Web site based on Active Server Pages (server-side scripting)
  • PHP - Embedded HTML scripting
  • VBScript - Windows based scripts
  • VBA - Visual Basic for Applications
  • Javascript - Java based scripts
  • HTML - Client scripts within HTML pages
  • ColdFusion - Server based web applications
  • Any other development platform that supports ActiveX/COM components

1.2. ActiveSocket Architecture

The core of ActiveSocket Toolkit is an ActiveX/COM component that comes in a 32-bit and a 64-bit version:

  • ASocket.dll - the 'ActiveSocket COM Component' for 32-bit platforms;
  • ASocketx64.dll - the 'ActiveSocket COM Component' for 64-bit platforms;

ActiveSocket can be distributed easily to any server and workstation in your network 9required a Processional License, see also Once you have purchased the licenses, you copy the ASocket.dll (or ASocketx64 for 64 bit applications) to the PCs and register the DLL on that PC. Click here for more information about the installation.

2. System requirements

2.1. Supported Operating Systems

ActiveSocket Toolkit can be used by any of the following operating systems:

  • Windows 2008 - x86 (32-bit) and x64 (64-bit)
  • Windows 2003 - x86 (32-bit) and x64 (64-bit)
  • Windows 2000 Server and Professional x86 (32-bit) only
  • Windows 7 - x86 (32-bit) and x64 (64-bit)
  • Windows Vista - x86 (32-bit) and x64 (64-bit)
  • Windows XP - x86 (32-bit) and x64 (64-bit)

NOTE: On 64 bits systems, you can run 32- and 64 bit programs. To integrate ActiveSocket in a 64-bit (web) application of service, use the 64-bit ASocketx64.dll. To integrate ActiveSocket in a 32-bit (web) application of service, use the 32-bit ASocket.dll.

2.2. Supported Development Platforms

The ActiveSocket Toolkit can be used by any of the following programming languages:

  • Visual Basic .NET
  • Visual C# .NET
  • Visual Basic 5.x or higher
  • Visual C++ 5.x or higher
  • Delphi 6.x or higher
  • ASP .NET
  • ASP 2.x
  • PHP
  • ColdFusion
  • VBScript
  • Javascript
  • HTML
  • Any other development platform that supports ActiveX/COM components

3. Installation

3.1. Introduction

The ActiveSocket Toolkit package consists of 3 components; any combination of components can be installed:

  • The ActiveSocket Toolkit COM component - the interface to COM compliant applications;
  • The ActiveSocket Toolkit Help Files - documentation;
  • The ActiveSocket Toolkit Sample Files - samples for various development platforms.

3.2. Installation on a single computer

Simply run the ASOCKET.EXE Setup program. The InstallShield wizard will guide you through the rest of the setup.
If you choose the ActiveSocket Toolkit COM component, the Setup program can perform the registration of the COM component for you. But it will also give you the opportunity to register the object yourself.

Any subsequent installation of ActiveSocket Toolkit can be performed either manually or by using the Setup program.

3.3. Installation on multiple computers

Any subsequent installations can be performed using the setup program.
But since the installation of the core components is very simple, you may want to do it manually, or integrate it into your companies software distribution program.

If you choose to install the COM component manually on other machines, simply perform the following actions:

  • Copy the ASocket.dll (for 32-bit platforms) or ASocketx64.dll (for 64-bit platforms) to a destination location on the new machine;
  • Register the COM component by using the following command on 32-bit platforms: REGSVR32 <dest-location>\ASocket.dll
  • Register the COM component by using the following command on 64-bit platforms: REGSVR32 <dest-location>\ASocketx64.dll

4. How to use ActiveSocket

4.1. Introduction

The following code snippets (VBScript) illustrate how to use various ActiveSocket objects.

DNS sample (list all records for a specific domain)
Set objDnsServer = CreateObject ( "ActiveXperts.DnsServer")     ' Create object
Set objConstants = CreateObject ( "ActiveXperts.ASConstants")

objDnsServer.Host       = "ns1.interstroom.nl"                  ' DNS server
      
' Show all DNS records for activexperts.com
objDnsServer.Lookup "activexperts.com", _
                    objConstants.asDNS_TYPE_ANY                 
WScript.Echo "Lookup, result: " & objDnsServer.LastError    
If( objDnsServer.LastError <> 0 ) Then
   WScript.Quit
End If

If ( objDnsServer.IsAuthoritative = True ) Then
   WScript.Echo "Server is an authority for this domain"
Else
   WScript.Echo "Server is not an authority for this domain"
End If
   
' Iterate over all DNS records; get first record
Set objDnsRecord = objDnsServer.GetFirstRecord                  
While ( objDnsServer.LastError = 0 )
   Select Case objDnsRecord.Type 
     Case objConstants.asDNS_TYPE_A
       WScript.Echo "Type             : A"
       WScript.Echo "Name             : " & objDnsRecord.Name
       WScript.Echo "IPv4 Address     : " & objDnsRecord.Address
     Case objConstants.asDNS_TYPE_AAAA
       WScript.Echo "Type             : AAAA"
       WScript.Echo "Name             : " & objDnsRecord.Name
       WScript.Echo "IPv6 Address     : " & objDnsRecord.Address
     Case objConstants.asDNS_TYPE_CNAME
       WScript.Echo "Type             : CNAME"
       WScript.Echo "Name             : " & objDnsRecord.Name
       WScript.Echo "Alias            : " & objDnsRecord.Address
     Case objConstants.asDNS_TYPE_MX 
       WScript.Echo "Type             : MX"
       WScript.Echo "Name             : " & objDnsRecord.Name
       WScript.Echo "Preference       : " & objDnsRecord.Preference
       WScript.Echo "Mail Exchange    : " & objDnsRecord.MailExchange
     Case objConstants.asDNS_TYPE_NS
       WScript.Echo "Type             : NS"
       WScript.Echo "Name             : " & objDnsRecord.Name
       WScript.Echo "Name Server      : " & objDnsRecord.NameServer
     Case objConstants.asDNS_TYPE_PTR
       WScript.Echo "Type             : PTR"
       WScript.Echo "Name             : " & objDnsRecord.Name
       WScript.Echo "Host             : " & objDnsRecord.Address
     Case objConstants.asDNS_TYPE_SOA
       WScript.Echo "Type             : SOA"
       WScript.Echo "Name             : " & objDnsRecord.Name
       WScript.Echo "Name Server      : " & objDnsRecord.NameServer
       WScript.Echo "MailBox          : " & objDnsRecord.MailBox
       WScript.Echo "Serial           : " & objDnsRecord.SerialNumber
       WScript.Echo "Refresh          : " & objDnsRecord.RefreshInterval
       WScript.Echo "Retry Interval   : " & objDnsRecord.RetryInterval
       WScript.Echo "Expiration Limit : " & objDnsRecord.ExpirationLimit
       WScript.Echo "Minimum TTL      : " & objDnsRecord.MinimumTTL
   End Select

   WScript.Echo "TTL              : " & objDnsRecord.TTL
   WScript.Echo
  
   ' Iterate over all DNS records; get next record
   Set objDnsRecord = objDnsServer.GetNextRecord                
Wend
FTP sample (list files in a specific directory on an FTP server)
Set objFtpServer = CreateObject ( "ActiveXperts.FtpServer" )

objFtpServer.Connect "ftp.activexperts-labs.com","anonymous","" ' Connect to the FTP server 
Wscript.Echo "Connect, result: " & objFtpServer.LastError
If( objFtpServer.LastError <> 0 ) Then                          ' If connect failed then quit
  WScript.Quit
End If

objFtpServer.ChangeDir "samples/network-component/Visual Basic/Telnet"    ' Change directory
Wscript.Echo "ChangeDir, result: " & objFtpServer.LastError
' If ChangeDir fails then disconnect and quit
If( objFtpServer.LastError <> 0 ) Then                          
  objFtpServer.Disconnect
  WScript.Quit
End If

' Iterate over all files; start with the first one
Set objFtpFile = objFtpServer.FindFirstFile()                   
While( objFtpServer.LastError = 0 )
  WScript.Echo "Name: " & objFtpFile.Name                       ' Display file name
  WScript.Echo "IsDirectory: " & objFtpFile.IsDirectory         ' Display directory or file
  WScript.Echo "Size: " & objFtpFile.Size                       ' Display file size
  WScript.Echo "Date: " & objFtpFile.Date                       ' Display file date
   
  ' To save the file, call the GetFile function. 
  ' strSaveAs = "C:\temp\" & objFtpFile.Name
  ' objFtpServer.GetFile objFtpFile.Name, strSaveAs
  ' Wscript.Echo "Save file, result: " & objFtpServer.LastError

  ' To delete a file, call the DeleteFile function. 
  ' objFtpServer.DeleteFile objFtpFile.Name
  ' Wscript.Echo "Delete, result: " & objFtpServer.LastError

  Set objFtpFile = objFtpServer.FindNextFile()                  ' Next file
Wend

objFtpServer.Disconnect                                         ' Disconnect
HTTP sample (read a web page)
Set objHttp = CreateObject( "ActiveXperts.Http" )               ' Create new Http instance
objHttp.ProxyServer   = "proxy01.intranet.dom"                  ' Proxy server  - if required
objHttp.ProxyAccount  = "mjackson"                              ' Proxy authentication
objHttp.ProxyPassword = "mjackson1"                             ' Proxy authentication
objHttp.Connect( "www.activexperts.com/products" )              ' Connect to a web server
WScript.Echo "Connect, result: " & objHttp.LastError
If( objHttp.LastError <> 0 ) Then
 WScript.Quit
End If
strData = objHttp.ReadData                                      ' Read web page data
WScript.Echo "ReadData, result: " & objHttp.LastError
If( objHttp.LastError <> 0 ) Then
 WScript.Echo strData                                           ' Display web page data
End If
objHttp.Disconnect
ICMP sample (ping a remote host)
Set objIcmp = CreateObject("ActiveXperts.Icmp")                 ' Create new Icmp instance
For i = 1 To 4                                                  ' Prepare for 4 consec. pings
  objIcmp.Ping "www.activexperts.com", 2000                     ' Ping host(time-out:2000 msecs)
  If( objIcmp.LastError = 0 ) Then
     WScript.Echo "Reply from " & strHost & _                   ' Display Ping results
                  ": time=" & objIcmp.LastDuration & "ms" & _   ' Display Duration
                  " TTL=" & objIcmp.LastTtl                     ' Display TTL
  Else
     WScript.Echo "Error " & objIcmp.LastError
  End If
Next
IP to Country sample (maps an IP address to a country
Set objIPC = CreateObject( "ActiveXperts.IPtoCountry" )         ' Create a new IPtoCountry inst.
objIPC.Host = "www.activexperts.com"                            ' Host name (or IP address) 
                                                                ' to resolve
objIPC.Query()                                                  ' Host name (or IP address) 
                                                                ' to resolve
WScript.Echo "Query, result: " & objIPC.LastError               ' Result of Query; 
                                                                ' 0 means: success
If objIPC.LastError = 0 Then
  WScript.Echo "Host " & strHost & " is located in " & objIPC.CountryName
End If
MSN sample (send an MSN message to a remote MSN recipient)
Set objMsn = CreateObject( "ActiveXperts.Msn" )                 ' Create Msn object

objMsn.Server       = "messenger2.hotmail.com"                  ' Use messenger2.hotmail.com
objMsn.MsnAccount   = "mymeself@activexperts.com"               ' Set MSN Account
objMsn.MsnPassword  = "topsecret"                               ' Set MSN Password

objMsn.Message      = "Hello World !!!!"                        ' Set MSN Message
objMsn.AddRecipient "mycollegue1@activexperts.com"              ' Add recipient(s)
objMsn.AddRecipient "mycollegue2@activexperts.com"               

objMsn.Send                                                     ' Send the message

WScript.Echo "Result : " & objMsn.LastError                     ' Display the result
NTP sample (query a remote time server)
Set objNtp = CreateObject("ActiveXperts.Ntp")                   ' Create new Ntp instance
objNtp.GetTime "fartein.ifi.uio.no"                             ' Query the time server
If( objNtp.LastError <> 0 ) Then
 WScript.Echo "Unable to retrieve time, error: " & objNtp.LastError
 WScript.Quit
End If

WScript.Echo "Time on timeserver: " & objNtp.Year & _           ' Display date and time
   "/" & objNtp.Month &  "/" & objNtp.Day & _                   ' Display date and time
   " " & objNtp.Hour & ":" &  objNtp.Minute & _                 ' Display date and time
   ":" &   objNtp.Second
WScript.Echo "DifferenceTime Server / Local PC: " & _           ' Display time offset
   objNtp.LocalOffsetSeconds & " seconds"                       ' Display time offset
End If
SNMP Walker (walk through the SNMP MIB database)
Set objSnmpManager = CreateObject( "ActiveXperts.SnmpManager" ) ' Create a new Snmp instance
objSnmpManager.Initialize                                       ' Initialize Snmp
objSnmpManager.Open "192.168.1.100", "public"
If( objSnmpManager.LastError = 0 )
 Set objSnmpObject = objSnmpManager.Get( "system.sysName.0" )   ' Get SnmpObject object
 While( objSnmpManager.LastError = 0 )
   WScript.Echo "Type:  " & objSnmpObject.Type
   WScript.Echo "Value: " & objSnmpObject.Value

   Set objSnmpObject = objSnmpManager.GetNext()                 ' Get next SnmpObject object
 End If
 objSnmpManager.Close
End If
objSnmpManager.Shutdown                                         ' Uninitialize Snmp
SNMP Traps (1 sender script, 1 receiver script)
' T R A P R E C E I V E R . V B S

' Create a new SnmpTrapManager instance
Set objTrapManager = CreateObject( "ActiveXperts.SnmpTrapManager" ) 
objTrapManager.Initialize                                       ' Initialize SNMP
If( objTrapManager.LastError <> 0 ) Then
  WScript.Quit
End If

objTrapManager.StartListening "public"                          ' Start listening now
If( objTrapManager.LastError <> 0 ) Then
  objTrapManager.Shutdown                                       ' Uninitialize SNMP
  WScript.Quit
End If

Set objSnmpTrap = objTrapManager.GetFirstTrap                   ' Get trap

While( objTrapManager.LastError = 0 )
  WScript.Echo "Trap from      : " & objSnmpTrap.Host
  WScript.Echo "  Community   : " & objSnmpTrap.Community

  Set objSnmpObject = objSnmpTrap.GetFirstObject      
  While( objSnmpTrap.LastError = 0 )                            ' Iterate over all variables 
                                                                ' in the trap
    
    WScript.Echo "OID : " & objSnmpObject.OID
    WScript.Echo "Value:" & objSnmpObject.Value   
    WScript.Echo "Type:"  & GetTypeString( objSnmpObject.Type )
  
    Set objSnmpObject = objSnmpTrap.GetNextObject
  WEnd

  Set objSnmpTrap = objTrapManager.GetNextTrap                  ' Get next trap
WEnd  

objTrapManager.StopListening                                    ' Stop listening for incoming 
                                                                ' traps
objTrapManager.Shutdown                                         ' Uninitialize SNMP
' T R A P S E N D E R . V B S

' Create a new SnmpTrapManager instance
Set objSnmpTrapManager = CreateObject("ActiveXperts.SnmpTrapManager") 

' Create a new SnmpTrap instance
Set objSnmpTrap        = CreateObject( "ActiveXperts.SnmpTrap" ) 

' Create a new SnmpObject instance
Set objSnmpObject      = CreateObject( "ActiveXperts.SnmpObject" )

' Create a new Constants instance 
Set objConstants       = CreateObject( "ActiveXperts.ASConstants" )
objSnmpTrapManager.Initialize                                   ' Initialize SNMP
If( objSnmpTrapManager.LastError <> 0 ) Then
  WScript.Quit
End If

' Set trap properties
objSnmpTrap.Clear()
objSnmpTrap.Host	  = "server06"
objSnmpTrap.Community = "public"

' Add a variable to the trap
objSnmpObject.Clear()                                           ' Clear trap object
objSnmpObject.OID   = ".1.3.6.1.2.1.1.5.0"                      ' Set trap properties
objSnmpObject.Type  = objConstants.asSNMP_TYPE_IPADDRESS        ' Set trap properties
objSnmpObject.Value = "10.0.0.1"                                ' Set trap properties 
objSnmpTrap.AddObject objSnmpObject                             ' Add the trap to the queue

' Add another variable to the trap
objSnmpObject.Clear()                                           ' Clear trap object
objSnmpObject.OID   = ".1.3.6.1.2.1.1.5.1"                      ' Set trap properties
objSnmpObject.Type  = objConstants.asSNMP_TYPE_OCTETSTRING      ' Set trap properties
objSnmpObject.Value = "One two three"                           ' Set trap properties 
objSnmpTrap.AddObject objSnmpObject                             ' Add the trap to the queue

objSnmpTrapManager.Send objSnmpTrap                             ' Send trap
WScript.Echo "Send, result: " & objSnmpTrapManager.LastError    ' Display the result

objSnmpTrapManager.Shutdown                                     ' Uninitialize SNMP
SSH sample (run a command on a remote LINUX/UNIX host in a secure way)
Set objSsh           = CreateObject("ActiveXperts.Ssh")         ' Create an Ssh instance
objSsh.Host          = "192.168.1.10"                           ' Hostname or IP address of 
                                                                ' remote UNIX/LINUX machine
objSsh.UserName      = "root"                                   ' Login as 'root'
objSsh.Password      = "topsecret"                              ' Use a password to login
objSsh.Command       = "/bin/ls"                                ' Command to execute
objSsh.ScriptTimeOut = 5000                                     ' Time-out (in milliseconds)
objSsh.Run                                                      ' Execute the command now
WScript.Echo "Run: result = " & objSsh.LastError 
If objSsh.LastError <> 0 Then
  WScript.Quit
End If

' YES, command has completed
WScript.Echo "StdErr: " & objSsh.StdErr                         ' Print Standard Output
WScript.Echo "StdOut: " & objSsh.StdOut                         ' Print Standard Error

WScript.Echo "Ready."
' S E R V E R . V B S
Set objTcp     = CreateObject("ActiveXperts.Tcp")               ' Create new Tcp instance
Set objConstants  = CreateObject( "ActiveXperts.ASConstants" )  ' Create a new Constants 
                                                                ' instance 
objTcp.Protocol= objConstants.asSOCKET_PROTOCOL_RAW             ' Plain TCP/IP communications

objTcp.StartListening 1500                                      ' Listen on port 1500
If objTcp.LastError <> 0 Then
  WScript.Echo "Error " & objTcp.LastError & ": " & _
    objTcp.GetErrorDescription( objTcp.LastError )
  WScript.Quit
End If

Do while objTcp.ConnectionState = objConstants.asSOCKET_CONNSTATE_LISTENING
  objTcp.Sleep 1000                                             ' Wait for incoming connection
Loop

If objTcp.ConnectionState = objConstants.asSOCKET_CONNSTATE_LISTENING Then
  str = ""                                                      ' Connection established
  Do While objTcp.ConnectionState = objConstants.asSOCKET_CONNSTATE_LISTENING and str <> "Quit"

     If objTcp.HasData Then
        str = objTcp.ReceiveString
        WScript.Echo "ReceiveString: " & str
     End If
     objTcp.Sleep 100
  Loop

  objTcp.Disconnect                                             ' And finally, disconnect
End If
TCP Client/Server application (1 client script, 1 server script)
' C L I E N T . V B S

Set objTcp     = CreateObject("ActiveXperts.Tcp")               ' Create new Tcp instance
Set objConstants  = CreateObject( "ActiveXperts.ASConstants" )  ' Create a new Constants inst. 
objTcp.Protocol= objConstants.asSOCKET_PROTOCOL_RAW             ' Plain TCP/IP communications

objTcp.Connect "127.0.0.1", 1500                                ' Connect to port 1500 on 
                                                                  remote server
WScript.Echo "Connect: result = " & objTcp.LastError
If objTcp.LastError <> 0	 Then
  WScript.Echo "Error #" & objTcp.LastError & ": " & _
    objTcp.GetErrorDescription( objTcp.LastError )
  WScript.Quit
End If

objTcp.SendString "This is a message"                           ' Send ASCII data
WScript.Echo "SendString, result: " & objTcp.LastError
objTcp.Sleep 1000                                               ' Hold script for 1000 msec

objTcp.SendString "Quit", False                                 ' Send ASCII data
objTcp.Disconnect                                               ' And finally, disconnect
Telnet sample (connect to a web site through a telnet session)
Set objTcp = CreateObject("ActiveXperts.Tcp")                   ' Create new Tcp instance
Set objConstants = CreateObject( "ActiveXperts.ASConstants" )   ' Create a new Constants inst. 
objTcp.Protocol = objConstants.asSOCKET_PROTOCOL_TELNET         ' Telnet communications

objTcp.Connect "www.activexperts.com", 80                       ' Connect to web site on 
                                                                  port 80
Wscript.Echo "Connect,, result: " & objTcp.LastError
If objTcp.LastError <> 0 Then
  WScript.Quit
End If

If objTcp.ConnectionState = objConstants.asSOCKET_CONNSTATE_CONNECTED Then

 strReceived = ""                                               ' Connection established
 objTcp.Sleep 1000

 objTcp.SendString "GET /activsocket/demopage/ HTTP/1.1"        ' Send string
 objTcp.SendString "Host: www.activexperts.com" & vbCrlf        ' Send string
 objTcp.Sleep 1000

 If objTcp.HasData Then
   strReceived = objTcp.ReceiveString                           ' Receive data
   WScript.Echo "RECV: " & strReceived
 End If
  
 objTcp.Sleep 1000 
 objTcp.Disconnect                                              ' Disconnect from server
End If
TFTP sample (download a file from a remote TFTP host, save it locally)
Set objTftpServer = CreateObject ( "ActiveXperts.TftpServer" ) 

objTftp.Get "10.1.1.10", "/folder1/file.txt", "c:\\file.txt"    ' Download file,save it locally 
Wscript.Echo "Get, result: " & objTftp.LastError 
If( objTftp.LastError <> 0 ) Then                               ' If download failed then quit
  WScript.Quit
End If

WScript.Echo "Packets received: " & objTftp.PacketsReceived     ' Print download statistics
WScript.Echo "Bytes received: " & objTftp.BytesReceived         ' Print download statistics
RSH sample (run a command on a remote LINUX/UNIX host in an unsecure way)
Set objRsh           = CreateObject("ActiveXperts.Rsh")         ' Create new Rsh instance
objRsh.Clear
objRsh.Host          = "192.168.1.10"                           ' Host/IP of the remote 
                                                                  UNIX/LINUX machine
objRsh.Command       = "/bin/ls"                                ' Command to execute on the 
                                                                  remote machine
objRsh.ScriptTimeOut = 5000                                     ' Time-out (in milliseconds)
objRsh.Run                                                      ' Run the command now
If objRsh.LastError <> 0 Then
 WScript.Echo "Error " & objRsh.LastError
WScript.Quit
End If

' YES, command has completed
WScript.Echo "StdErr: " & objRsh.StdErr                         ' Display stdout
WScript.Echo "StdOut: " & objRsh.StdOut                         ' Display stderr
UDP Client/Server application (1 client script, 1 server script)
' C L I E N T . V B S

' Create a socket instance
Set objUdp       = CreateObject ( "ActiveXperts.Udp" )
Set objConstants = CreateObject ( "ActiveXperts.ASConstants" )

' Write some information to console
WScript.Echo "ActiveSocket " & objUdp.Version & " demo."
WScript.Echo "Expiration date: " & objUdp.ExpirationDate & vbCrLf

' Open socket to send to port 1500 on remote server
objUdp.Open "localhost", 1500, False
WScript.Echo "Open, result: " & objUdp.LastError & _
            " (" & objUdp.GetErrorDescription( objUdp.LastError ) & ")"
If( objUdp.LastError <> 0 ) Then
  WScript.Echo "Ready."
  WScript.Quit
End If

str = "This is just a message"
objUdp.SendString str                                           ' Send message
WScript.Echo "SendString '" & str & "': result = " & objUdp.LastError
objUdp.Sleep 100

str = "And this is another message"
objUdp.SendString str                                           ' Send another message
WScript.Echo "SendString '" & str & "': result = " & objUdp.LastError
objUdp.Sleep 100

str = "Quit"
objUdp.SendString str                                           ' Send last message
WScript.Echo "SendString '" & str & "': result = " & objUdp.LastError
objUdp.Sleep 100

objUdp.Close                                                    ' And finally, close the socket


' S E R V E R . V B S
' Create a socket instance
Set objUdp       = CreateObject ( "ActiveXperts.Udp" )
Set objConstants = CreateObject ( "ActiveXperts.ASConstants" )

' Write some information to console
WScript.Echo "ActiveSocket " & objUdp.Version & " demo."
WScript.Echo "Expiration date: " & objUdp.ExpirationDate & vbCrLf

' Open socket to receive UDP datagrams on port 1500 on this machine
objUdp.Open "localhost", 1500, True
WScript.Echo "Open, result: " & objUdp.LastError & _
            " (" & objUdp.GetErrorDescription( objUdp.LastError ) & ")"
If( objUdp.LastError <> 0 ) Then
  WScript.Echo "Ready."
  WScript.Quit
End If

Do While str <> "Quit"
  str = objUdp.ReceiveString                                    ' Receive message	
  If( objUdp.LastError = 0 And str <> "" ) Then
      WScript.Echo "ReceiveString: " & str
  End If	
  objUdp.Sleep ( 100 )
Loop

objUdp.Close
Wake_On-LAN sample (Power-Up a remote computer)
Set objWOL = CreateObject( "ActiveXperts.WOL" )                 ' Create a new WOL instance
strMAC = "00-10-4B-BA-7A-51"
objWOL.WakeUp strMAC                                            ' Send magic packet to remote 
                                                                ' station identified by MAC
WScript.Echo "WakeUp, result = " & objWOL.LastError             ' Display the result

4.2. Visual Basic .NET

Make sure the ActiveSocket Toolkit is installed on your system. For details about installation, click here.

Add a reference to the object using the Visual Basic Solution Explorer:

  • Start the Solution Provider, go to the project's 'References' container;
  • Choose 'Add Reference' from the context menu;
  • Select the COM tab, choose the 'ActiveSocket Toolkit' component.

You can use different ActiveSocket objects in one Visual Basic .NET application. The following code shows how to declare and create all ActiveSocket objects:

Imports ASocket

Dim objConstants As SocketConstants                             ' Declaration
objConstants = New SocketConstants()                            ' Creation

Dim objDnsServer As DnsServer                                   ' Declaration
objDnsServer = New DnsServer()                                  ' Creation
Dim objDnsRecord As DnsRecord                                   ' Declaration
objDnsRecord = New DnsRecord()                                  ' Creation

Dim objFtpServer As FtpServer                                   ' Declaration
objFtpServer = New FtpServer()                                  ' Creation
Dim objFtpFile As FtpFile                                       ' Declaration
objFtpFile = New FtpFile()                                      ' Creation

Dim objHttp As Http                                             ' Declaration
objHttp = New Http()                                            ' Creation

Dim objIcmp As Icmp                                             ' Declaration
objIcmp = New Icmp()                                            ' Creation

Dim objIPC As IPtoCountry                                       ' Declaration
objIPC = New IPtoCountry()                                      ' Creation

Dim objMsn As Msn                                               ' Declaration
objMsn = New Msn()                                              ' Creation

Dim objNtp As Ntp                                               ' Declaration
objNtp = New Ntp()                                              ' Creation

Dim objRsh As Rsh                                               ' Declaration
objRsh = New Rsh()                                              ' Creation

Dim objScp As Scp                                               ' Declaration
objScp = New Scp()                                              ' Creation

Dim objSFtpServer As SFtpServer                                 ' Declaration
objSFtpServer = New SFtpServer()                                ' Creation
Dim objSFtpFile As SFtpFile                                     ' Declaration
objSFtpFile = New SFtpFile()                                    ' Creation

Dim objSnmpTrapManager As SnmpTrapManager                       ' Declaration
objSnmpTrapManager = New SnmpTrapManager()                      ' Creation
Dim objSnmpTrap As SnmpTrap                                     ' Declaration
objSnmpTrap = New SnmpTrap()                                    ' Creation

Dim objSnmpMib As SnmpMibBrowser                                ' Declaration
objSnmpMib = New SnmpMibBrowser()                               ' Creation

Dim objSsh As Ssh                                               ' Declaration
objSsh = New Ssh()                                              ' Creation

Dim objTcp As Tcp                                               ' Declaration
objTcp = New Tcp()                                              ' Creation

Dim objTftpServer As TftpServer                                 ' Declaration
objTftpServer = New TftpServer()                                ' Creation

Dim objUdp As Udp                                               ' Declaration
objUdp = New Udp()                                              ' Creation

Dim objWOL As WOL                                               ' Declaration
objWOL = New WOL()                                              ' Creation

After these declarations and creation of the object(s), you can use the objects inside your Visual Basic .NET project.

4.3. Visual C# .NET

Make sure the ActiveSocket Toolkit is installed on your system. For details about installation, click here.

Add a reference to the object using the Visual C# Solution Explorer:

  • Start the Solution Provider, go to the project's 'References' container;
  • Choose 'Add Reference' from the context menu;
  • Select the COM tab, choose the 'ActiveSocket Toolkit' component.

You can use different ActiveSocket objects in one Visual C# .NET application. The following code shows how to declare and create the ActiveSocket objects:

using ASOCKETLib

SocketConstants objConstants;                                   // Declaration
objConstants = new SocketConstants();                           // Creation

DnsServer objDnsServer;                                         // Declaration
objDnsServer = new DnsServer();                                 // Creation
DnsRecord objDnsRecord;                                         // Declaration
objDnsRecord = new DnsRecord();                                 // Creation

Http objHttp;                                                   // Declaration
objHttp = new Http();                                           // Creation

Icmp objIcmp;                                                   // Declaration
objIcmp = new Icmp();                                           // Creation

IPtoCountry objIPC;                                             // Declaration
objIPC = new IPtoCountry();                                     // Creation

FtpServer objFtpServer;                                         // Declaration
objFtpServer = new FtpServer();                                 // Creation
FtpFile objFtpFile;                                             // Declaration
objFtpFile = new FtpFile();                                     // Creation

Msn objMsn;                                                     // Declaration
objMsn = new Msn();                                             // Creation

Ntp objNtp;                                                     // Declaration
objNtp = new Ntp();                                             // Creation

Rsh objRsh                                                      // Declaration
objRsh = new Rsh();                                             // Creation

Scp objScp                                                      // Declaration
objScp = new Scp();                                             // Creation

SFtpServer objSFtpServer;                                       // Declaration
objSFtpServer = new SFtpServer();                               // Creation
SFtpFile objSFtpFile;                                           // Declaration
objSFtpFile = new SFtpFile();                                   // Creation

SnmpManager objSnmpManager;                                     // Declaration
objSnmpManager = new SnmpManager();                             // Creation
SnmpObject objSnmObject;                                        // Declaration
objSnmpObject = new SnmpObject();                               // Creation

SnmpTrapManager objSnmpTrapManager;                             // Declaration
objSnmpTrapManager = new SnmpTrapManager();                     // Creation
SnmpTrap objSnmpTrap;                                           // Declaration
objSnmpTrap = new SnmpTrap();                                   // Creation

SnmpMibBrowser objSnmpMib;                                      // Declaration
objSnmpMib = new SnmpMibBrowser();                              // Creation

Ssh objSsh                                                      // Declaration
objSsh = new Ssh();                                             // Creation

Tcp objTcp;                                                     // Declaration
objTcp = new Tcp();                                             // Creation

TftpServer objTftpServer;                                       // Declaration
objTftpServer = new TftpServer();                               // Creation

Udp objUdp;                                                     // Declaration
objUdp = new Udp();                                             // Creation

WOL objWOL;                                                     // Declaration
objWOL = new WOL();                                             // Creation

After these declarations and creation of the object(s), you can use the objects inside your Visual C# .NET project.

4.4. Visual Basic

ActiveSocket can be used in Visual Basic 5.x or higher. In Visual Basic, go to the 'Project/References...' menu item and check the box next to ActiveSocket Type Library. Now, you can declare and create ActiveSocket objects.

Create new ActiveSocket objects using the 'CreateObject' function:

Dim objConstants As ASOCKETLib.SocketConstants                  ' Declaration
Set objConstants = CreateObject( "ActiveXperts.ASConstants" )   ' Creation

Dim objDnsServer As ASOCKETLib.DnsServer                        ' Declaration
Set objDnsServer = CreateObject( "ActiveXperts.DnsServer" )     ' Creation
Dim objDnsRecord  As ASOCKETLib.DnsRecord                       ' Declaration
Set objDnsRecord = CreateObject( "ActiveXperts.DnsRecord")      ' Creation

Dim objIcmp As ASOCKETLib.Icmp                                  ' Declaration
Set objIcmp = CreateObject( "ActiveXperts.Icmp" )               ' Creation

Dim objIPC  As ASOCKETLib.IPtoCountry                           ' Declaration
Set objIPC = CreateObject( "ActiveXperts.IPtoCountry")          ' Creation

Dim objFtpServer As ASOCKETLib.FtpServer                        ' Declaration
Set objFtpServer = CreateObject( "ActiveXperts.FtpServer" )     ' Creation
Dim objFtpFile  As ASOCKETLib.FtpFile                           ' Declaration
Set objFtpFile = CreateObject( "ActiveXperts.FtpFile")          ' Creation

Dim objHttp As ASOCKETLib.Http                                  ' Declaration
Set objHttp = CreateObject( "ActiveXperts.Http" )               ' Creation

Dim objMsn  As ASOCKETLib.Msn                                   ' Declaration
Set objMsn = CreateObject( "ActiveXperts.Msn")                  ' Creation

Dim objNtp As ASOCKETLib.Ntp                                    ' Declaration
Set objNtp = CreateObject( "ActiveXperts.Ntp" )                 ' Creation

Dim objRsh As ASOCKETLib.Rsh                                    ' Declaration
Set objRsh = CreateObject( "ActiveXperts.Rsh" )                 ' Creation

Dim objScp As ASOCKETLib.Scp                                    ' Declaration
Set objScp = CreateObject( "ActiveXperts.Scp" )                 ' Creation

Dim objSFtpServer As ASOCKETLib.SFtp                            ' Declaration
Set objSFtpServer = CreateObject( "ActiveXperts.SFtp" )         ' Creation
Dim objSFtpFile  As ASOCKETLib.SFtpFile                         ' Declaration
Set objSFtpFile = CreateObject( "ActiveXperts.SFtpFile")        ' Creation

Dim objSnmpManager  As ASOCKETLib.SnmpManager                   ' Declaration
Set objSnmpManager = CreateObject( "ActiveXperts.SnmpManager" ) ' Creation
Dim objSnmpObject As ASOCKETLib.SnmpObject                      ' Declaration
Set objSnmpObject = CreateObject( "ActiveXperts.SnmpObject")    ' Creation

Dim objSnmpTrapManager  As ASOCKETLib.SnmpTrapManager           ' Declaration
Set objSnmpTrapManager = CreateObject( "ActiveXperts.SnmpTrapManager" )  ' Creation
Dim objSnmpTrap As ASOCKETLib.SnmpTrap                          ' Declaration
Set objSnmpTrap = CreateObject( "ActiveXperts.SnmpTrap" )       ' Creation

Dim objSnmpMib As ASOCKETLib.SnmpMibBrowser                     ' Declaration
Set objSnmpMib = CreateObject( "ActiveXperts.SnmpMibBrowser" )  ' Creation

Dim objSsh As ASOCKETLib.Ssh                                    ' Declaration
Set objSsh = CreateObject( "ActiveXperts.Ssh" )                 ' Creation

Dim objTcp As ASOCKETLib.Tcp                                    ' Declaration
Set objTcp = CreateObject( "ActiveXperts.Tcp" )                 ' Creation

Dim objTftpServer As ASOCKETLib.TftpServer                      ' Declaration
Set objTftpServer = CreateObject( "ActiveXperts.TftpServer" )   ' Creation

Dim objUdp As ASOCKETLib.Udp                                    ' Declaration
Set objUdp = CreateObject( "ActiveXperts.Udp" )                 ' Creation

Dim objWOL  As ASOCKETLib.WOL                                   ' Declaration
Set objWOL = CreateObject( "ActiveXperts.WOL")                  ' Creation

After these declarations and creation of the object(s), you can use the objects inside your Visual Basic 5.x/6.x project.

4.5. Visual C++

ActiveSocket can be used in Visual C++ projects. Include the *.h and *.c file provided by ActiveXperts to bind your code to the ActiveSocket component. These files are located in the Include directory of the Visual C++ samples directory. These are the files:

  • ASocket.h
  • ASocket_i.c
  • ASocketConstants.h

Declare and create new ActiveSocket objects like this:

ISocketConstants *pConstants;                                    
CoCreateInstance(
  CLSID_SocketConstants, 
  NULL, 
  CLSCTX_INPROC_SERVER, 
  IID_ISocketConstants, 
  (void**) &pConstants );

IDnsServer *pDnsServer;              
CoCreateInstance(
  CLSID_DnsServer, 
  NULL, 
  CLSCTX_INPROC_SERVER, 
  IID_IDnsServer, 
  (void**) &pDnsServer ); 
  
IDnsRecord *pDnsRecord;             
CoCreateInstance(
  CLSID_DnsRecord, 
  NULL, 
  CLSCTX_INPROC_SERVER, 
  IID_IDnsRecord, 
  (void**) &pDnsRecord );

IFtpServer *pFtpServer;           
CoCreateInstance(
  CLSID_FtpServer, 
  NULL, 
  CLSCTX_INPROC_SERVER, 
  IID_IFtpServer, 
  (void**) &pFtpServer ); 
  
IFtpFile *pFtpFile;               
CoCreateInstance(
  CLSID_FtpFile, 
  NULL, 
  CLSCTX_INPROC_SERVER, 
  IID_IFtpFile, (void**) &pFtpFile ); 

IXHttp *pHttp;                     
CoCreateInstance(
  CLSID_Http, 
  NULL, 
  CLSCTX_INPROC_SERVER, 
  IID_IXHttp, 
  (void**) &pHttp ); 

IIcmp *pIcmp;                                                          
CoCreateInstance(
  CLSID_Icmp, NULL, 
  CLSCTX_INPROC_SERVER, 
  IID_IIcmp, (void**) &pIcmp );

IIPtoCountry *pIPC;               
CoCreateInstance(
  CLSID_IPtoCountry, 
  NULL, 
  CLSCTX_INPROC_SERVER, 
  IID_IIPtoCountry, 
  (void**) &pIPC ); 
            
IMsn *pMsn;               
CoCreateInstance(
  CLSID_Msn, 
  NULL, 
  CLSCTX_INPROC_SERVER, 
  IID_IMsn, 
  (void**) &pMsn ); 

INtp *pNtp;                       
CoCreateInstance(
  CLSID_Ntp, 
  NULL, 
  CLSCTX_INPROC_SERVER, 
  IID_INtp, 
  (void**) &pNtp );

IRSh *pRsh;                         
CoCreateInstance(
  CLSID_RSh, 
  NULL, 
  CLSCTX_INPROC_SERVER, 
  IID_IRSh, 
  (void**) &pRSh );

IScp *pScp;                       
CoCreateInstance(
  CLSID_Scp, 
  NULL, 
  CLSCTX_INPROC_SERVER, 
  IID_IScp, 
  (void**) &pScp );

ISFtpServer *pSFtpServer;           
CoCreateInstance(
  CLSID_SFtpServer, 
  NULL, 
  CLSCTX_INPROC_SERVER, 
  IID_ISFtpServer, 
  (void**) &pSFtpServer );  
  
ISFtpFile *pSFtpFile;               
CoCreateInstance( 
  CLSID_SFtpFile, 
  NULL, 
  CLSCTX_INPROC_SERVER, 
  IID_ISFtpFile, 
  (void**) &pSFtpFile ); 

ISnmpManager *pSnmpManager;     
CoCreateInstance(
  CLSID_SnmpManager, 
  NULL, 
  CLSCTX_INPROC_SERVER, 
  IID_ISnmpManager, 
  (void**) &pSnmpManager );

ISnmpObject *pSnmpObject;          
CoCreateInstance(
  CLSID_SnmpObject, 
  NULL, 
  CLSCTX_INPROC_SERVER, 
  IID_ISnmpObject, 
  (void**) &pSnmpObject ); 

ISnmpTrapManager *pSnmpTrapManager;  
CoCreateInstance(
  CLSID_SnmpTrapManager, 
  NULL, 
  CLSCTX_INPROC_SERVER, 
  IID_ISnmpTrapManager, 
  (void**) &pSnmpTrapManager );
  
ISnmpTrap *pSnmpTrap;              
CoCreateInstance(
  CLSID_SnmpTrap, 
  NULL, 
  CLSCTX_INPROC_SERVER, 
  IID_ISnmpTrap, 
  (void**) &pSnmpTrap );    

ISnmpMibBrowser *pSnmpMib;        
CoCreateInstance(
  CLSID_SnmpMibBrowser, 
  NULL, 
  CLSCTX_INPROC_SERVER, 
  IID_ISnmpMibBrowser, 
  (void**) &pSnmpMib ); 

ISsh *pSsh;                       
CoCreateInstance(
  CLSID_Ssh, 
  NULL, 
  CLSCTX_INPROC_SERVER, 
  IID_ISsh, 
  (void**) &pSsh );

ITcp *pTcp;                          
CoCreateInstance(
  CLSID_Tcp, 
  NULL, 
  CLSCTX_INPROC_SERVER, 
  IID_ITcp, 
  (void**) &pTcp );

ITftpServer *pTftpServer;         
CoCreateInstance(
  CLSID_TftpServer, 
  NULL, 
  CLSCTX_INPROC_SERVER, 
  IID_ITftpServer, 
  (void**) &pTftpServer );

IUdp *pUdp;                         
CoCreateInstance(
  CLSID_Udp, 
  NULL, 
  CLSCTX_INPROC_SERVER, 
  IID_IUdp, 
  (void**) &pUdp );

IWOL *pWol;                         
CoCreateInstance(
  CLSID_WOL, 
  NULL, 
  CLSCTX_INPROC_SERVER, 
  IID_IWOL, 
  (void**) &pWOL ); 

Visual C++ samples are installed as part of the product, but can also be found on our website.

4.6. ASP 2.x

<html>
  <body>
  Version:
  <script language="vbscript" runat="server">
    Set objTcp = CreateObject( "ActiveXperts.Tcp" )
    Response.Write objTcp.Version
  </script>
  </body>
</html>

4.7. Delphi 7.x or higher

Make sure the ActiveSocket Toolkit is installed on your system. For details about installation, click here.

First, add a reference to the ActiveSocket objects:

  • Go to Project->Import Type Library;
  • Select 'ActiveSocket 3.x Type Library';
  • Click 'Install';
  • The project 'dclusr.dpk' will be opened. Click 'Yes';
  • You can now use the ActiveSocket toolkit within your application by selecting the component from the 'ActiveX' component bar.

Create the various ActiveSocket object instances like this:

{ Declaration of the interface class  }
objConst      : ISocketConstants;                                 
{ Creation new instance of the object }
objConst      := TSocketConstants.Create(Form1).DefaultInterface; 

{ Declaration of the interface class  }
objDnsServer  : IDnsServer;                                       
{ Creation new instance of the object }       
objDnsServer  := TDnsServer.Create(Form1).DefaultInterface;       
{ Declaration of the interface class  }
objDnsRecord  : IDnsRecord;                                       
{ Creation new instance of the object }
objDnsRecord  := TDnsRecord.Create(Form1).DefaultInterface;       

{ Declaration of the interface class  }
objHttp       : IXHttp;                                            
{ Creation new instance of the object }       
objHttp       := THttp.Create(Form1).DefaultInterface;            

{ Declaration of the interface class  }
objFtpServer  : IFtpServer;                                       
{ Creation new instance of the object }       
objFtpServer  := TFtpServer.Create(Form1).DefaultInterface;       
{ Declaration of the interface class  }
objFtpFile    : IFtpFile;                                         
{ Creation new instance of the object }  
objFtpFile    := TFtpFile.Create(Form1).DefaultInterface;         

{ Declaration of the interface class  }
objIcmp       : IICmp;                                            
{ Creation new instance of the object }       
objIcmp       := TIcmp.Create(Form1).DefaultInterface;            

{ Declaration of the interface class  }
objIPC        : IIPtoCountry;                                     
{ Creation new instance of the object }        
objIPC        := TIPtoCountry.Create(Form1).DefaultInterface;     

{ Declaration of the interface class  }
objMsn        : IMsn;                                             
{ Creation new instance of the object }       
objMsn        := TMsn.Create(Form1).DefaultInterface;             

{ Declaration of the interface class  }
objNtp        : INtp;                                             
{ Creation new instance of the object }       
objNtp        := TNtp.Create(Form1).DefaultInterface;             
       
{ Declaration of the interface class  }
objRsh        : IRSh;                                             
{ Creation new instance of the object }       
objRsh        := TRSh.Create(Form1).DefaultInterface;             

{ Declaration of the interface class  }
objScp        : IScp;                                             
{ Creation new instance of the object }       
objScp        := TScp.Create(Form1).DefaultInterface;             

{ Declaration of the interface class  }
objSFtpServer : ISFtpServer;                                      
{ Creation new instance of the object }       
objSFtpServer := STFtpServer.Create(Form1).DefaultInterface;      
{ Declaration of the interface class  }
objSFtpFile   : ISFtpFile;                                        
{ Creation new instance of the object }  
objSFtpFile   := STFtpFile.Create(Form1).DefaultInterface;        

{ Declaration of the interface class  }
objManager    : ISnmpManager;                                     
{ Creation new instance of the object }       
objManager    := TSnmpManager.Create(Form1).DefaultInterface;     
{ Declaration of the interface class  }
objSnmpObject : ISnmpObject;                                      
{ Creation new instance of the object }       
objSnmpObject := TSnmpObject.Create(Form1).DefaultInterface;      

{ Declaration of the interface class  }
objManager    : ISnmpTrapManager;                                 
{ Creation new instance of the object }       
objManager    := TSnmpTrapManager.Create(Form1).DefaultInterface; 
{ Declaration of the interface class  }
objData       : ISnmpTrapData;                                    
{ Creation new instance of the object }       
objData       := TSnmpTrapData.Create(Form1).DefaultInterface;    

{ Declaration of the interface class  }
objSnmpMib    : ISnmpMibBrowser;                                  
{ Creation new instance of the object }           
objSnmpMib    := TSnmpMibBrowser.Create(Form1).DefaultInterface;  

{ Declaration of the interface class  }
objSsh        : ISsh;                                             
{ Creation new instance of the object }       
objSsh        := TSsh.Create(Form1).DefaultInterface;             

{ Declaration of the interface class  }
objTcp        : ITcp;                                             
{ Creation new instance of the object }
objTcp        := TTcp.Create(Form1).DefaultInterface;             

{ Declaration of the interface class  }
objTftpServer : ITftpServer;                                      
{ Creation new instance of the object }       
objTftpServer := TFtpServer.Create(Form1).DefaultInterface;       

{ Declaration of the interface class  }
objUdp        : IUdp;                                             
{ Creation new instance of the object }
objUdp        := TUdp.Create(Form1).DefaultInterface;             

{ Declaration of the interface class  }
objWOL        : IWOL;                                             
{ Creation new instance of the object }       
objWOL        := TWOL.Create(Form1).DefaultInterface;             

After these declarations and creation of the object(s), you can use the objects in your Delphi projects.

5. DnsServer

5.1. Introduction

DNS is the Domain Name System. DNS converts machine names to the IP addresses that all machines on the net have. It translates (i.e. 'maps') from name to address and from address to name, and some other things.

The ActiveSocket DNS objects can be used to query servers running a domain name service (DNS) application. It will send domain name query packets to any designated DNS server. There are three data elements required in order to formulate a DNS query using ActiveSocket:

  • DNS servername/address
  • Internet style address that is being queried
  • Type of record you are searching for

The ActiveSocket DNS objects are useful for gathering address information about hosts in the network. It can be used to query DNS for specific information about hosts, like mail exchanger records [MX], IP address [A], canonical names [CNAME], etc. If you have an IP address, you can get a canonical name back for the address and vice versa. Another useful feature is the ability to get a listing of hosts which serve mail exchange [MX] functions for a specific domain.

The following sample (VBScript) shows how the DnsServer and DnsRecord objects can be used to list all DNS records for a specific domain name:

    
Set objDnsServer = CreateObject ( "ActiveXperts.DnsServer")     ' Create object
Set objConstants = CreateObject ( "ActiveXperts.ASConstants")

objDnsServer.Host       = "ns1.interstroom.nl"                  ' DNS server
       
objDnsServer.Lookup "activexperts.com", _
  objConstants.asDNS_TYPE_ANY                                   ' Show all DNS records 
                                                                  for activexperts.com
WScript.Echo "Lookup, result: " & objDnsServer.LastError    
If( objDnsServer.LastError <> 0 ) Then
    WScript.Quit
End If

If ( objDnsServer.IsAuthoritative = True ) Then
    WScript.Echo "Server is an authority for this domain"
Else
    WScript.Echo "Server is not an authority for this domain"
End If
    
Set objDnsRecord = objDnsServer.GetFirstRecord                  ' Iterate over all DNS 
                                                                ' records; get first record   	
While ( objDnsServer.LastError = 0 )
    Select Case objDnsRecord.Type 
      Case objConstants.asDNS_TYPE_A
        WScript.Echo "Type             : A"
        WScript.Echo "Name             : " & objDnsRecord.Name
        WScript.Echo "IPv4 Address     : " & objDnsRecord.Address
      Case objConstants.asDNS_TYPE_AAAA
        WScript.Echo "Type             : AAAA"
        WScript.Echo "Name             : " & objDnsRecord.Name
        WScript.Echo "IPv6 Address     : " & objDnsRecord.Address
      Case objConstants.asDNS_TYPE_CNAME
        WScript.Echo "Type             : CNAME"
        WScript.Echo "Name             : " & objDnsRecord.Name
        WScript.Echo "Alias            : " & objDnsRecord.Address
      Case objConstants.asDNS_TYPE_MX 
        WScript.Echo "Type             : MX"
        WScript.Echo "Name             : " & objDnsRecord.Name
        WScript.Echo "Preference       : " & objDnsRecord.Preference
        WScript.Echo "Mail Exchange    : " & objDnsRecord.MailExchange
      Case objConstants.asDNS_TYPE_NS
        WScript.Echo "Type             : NS"
        WScript.Echo "Name             : " & objDnsRecord.Name
        WScript.Echo "Name Server      : " & objDnsRecord.NameServer
      Case objConstants.asDNS_TYPE_PTR
        WScript.Echo "Type             : PTR"
        WScript.Echo "Name             : " & objDnsRecord.Name
        WScript.Echo "Host             : " & objDnsRecord.Address
      Case objConstants.asDNS_TYPE_SOA
        WScript.Echo "Type             : SOA"
        WScript.Echo "Name             : " & objDnsRecord.Name
        WScript.Echo "Name Server      : " & objDnsRecord.NameServer
        WScript.Echo "MailBox          : " & objDnsRecord.MailBox
        WScript.Echo "Serial           : " & objDnsRecord.SerialNumber
        WScript.Echo "Refresh          : " & objDnsRecord.RefreshInterval
        WScript.Echo "Retry Interval   : " & objDnsRecord.RetryInterval
        WScript.Echo "Expiration Limit : " & objDnsRecord.ExpirationLimit
        WScript.Echo "Minimum TTL      : " & objDnsRecord.MinimumTTL
    End Select
  
    WScript.Echo "TTL              : " & objDnsRecord.TTL
    WScript.Echo
    
    Set objDnsRecord = objDnsServer.GetNextRecord               ' Iterate over all DNS 
                                                                ' records; get next record
Wend

5.2. Properties

Properties

Property Type Read/Write Description
Name String Out Name of the record
Type Number Out Type of DNS record
Address String Out IP address (or name of A record in case of CNAME)
TTL Number Out Used as the default TTL for new records created within the zone
MailExchange String Out The email address (replace @ with a dot) of the person responsible for maintenance of the zone
Preference String Out MX preference
NameServer String Out The domain name of the primary DNS server for the zone
MailBox String Out The email address (replace @ with a dot) of the person responsible for maintenance of the zone
SerialNumber String Out Used by secondary DNS servers to check if the zone has changed
RefreshInterval Number Out How often secondary DNS servers should check if changes are made to the zone
RetryInterval Number Out How often secondary DNS server should retry checking if changes are made - if the first refresh fails
ExpirationLimit Number Out How long the zone will be valid after a refresh
MinimumTTL Number Out Used as the default TTL for new records created within the zone

Name property

Type:

String

Description:

Name of the record.

Example:

Set objDnsServer = CreateObject ( "ActiveXperts.DnsServer")     ' Create a new DnsServer 
                                                                ' instance
Set objConstants = CreateObject ( "ActiveXperts.ASConstants")

objDnsServer.Server  = "ns1.interstroom.nl"                     ' Apply queries to DNS 
                                                                ' server ns1.interstroom.nl    
objDnsServer.Lookup "activexperts.com", _ 
  objConstants.asDNS_TYPE_ANY                                   ' Lookup any dns record 
                                                                ' for activexperts.com    
If( objDnsServer.LastError = 0 ) Then
    WScript.Quit
End If
Set objDnsRecord = objDnsServer.GetFirstRecord                  ' Get first DNS record 
If( objDnsServer.LastError = 0 ) Then
    WScript.Echo "Name: " & objDnsRecord.Name
    WScript.Echo "Type: " & objDnsRecord.Type
    WScript.Echo "Address: " & objDnsRecord.Address
End If

Type property

Type:

Number

Description:

Type of DNS record. Click here for a list of valid DNS types.

Example:

Set objDnsServer = CreateObject ( "ActiveXperts.DnsServer")     ' Create a new DnsServer 
                                                                ' instance
Set objConstants = CreateObject ( "ActiveXperts.ASConstants")

objDnsServer.Server  = "ns1.interstroom.nl"                     ' Apply queries to DNS server 
                                                                ' ns1.interstroom.nl    
objDnsServer.Lookup "activexperts.com", _
  objConstants.asDNS_TYPE_ANY                                   ' Lookup any dns record for 
                                                                ' activexperts.com    
If( objDnsServer.LastError = 0 ) Then
    WScript.Quit
End If
Set objDnsRecord = objDnsServer.GetFirstRecord                  ' Get first DNS record 
If( objDnsServer.LastError = 0 ) Then
    WScript.Echo "Name: " & objDnsRecord.Name
    WScript.Echo "Type: " & objDnsRecord.Type
    WScript.Echo "Address: " & objDnsRecord.Address
End If

Address property

Type:

String

Description:

IP Address, or name of A record (in case of a CNAME).

Example:

Set objDnsServer = CreateObject ( "ActiveXperts.DnsServer")     ' Create a new DnsServer 
                                                                ' instance
Set objConstants = CreateObject ( "ActiveXperts.ASConstants")

objDnsServer.Server  = "ns1.interstroom.nl"                     ' Apply queries to DNS 
                                                                ' server ns1.interstroom.nl    
objDnsServer.Lookup "activexperts.com", _ 
  objConstants.asDNS_TYPE_ANY                                   ' Lookup any dns record 
                                                                ' for activexperts.com    
If( objDnsServer.LastError = 0 ) Then
    WScript.Quit
End If
Set objDnsRecord = objDnsServer.GetFirstRecord                  ' Get first DNS record 
If( objDnsServer.LastError = 0 ) Then
    WScript.Echo "Name: " & objDnsRecord.Name
    WScript.Echo "Type: " & objDnsRecord.Type
    WScript.Echo "Address: " & objDnsRecord.Address
End If

TTL property

Type:

Number

Description:

Used as the default TTL for new records created within the zone.

Example:

Set objDnsServer = CreateObject ( "ActiveXperts.DnsServer")     ' Create a new DnsServer 
                                                                ' instance
Set objConstants = CreateObject ( "ActiveXperts.ASConstants")

objDnsServer.Server  = "ns1.interstroom.nl"                     ' Apply queries to DNS 
                                                                ' server ns1.interstroom.nl    
objDnsServer.Lookup "activexperts.com", _ 
  objConstants.asDNS_TYPE_ANY                                   ' Lookup any dns record 
                                                                ' for activexperts.com    
If( objDnsServer.LastError = 0 ) Then
    WScript.Quit
End If
Set objDnsRecord = objDnsServer.GetFirstRecord                  ' Get first DNS record 
If( objDnsServer.LastError = 0 ) Then
    WScript.Echo "Name: " & objDnsRecord.Name
    WScript.Echo "TTL: " & objDnsRecord.TTL
End If

MailExchange property

Type:

String

Description:

The A Record for the mail server to connect to its IP-address. The 'MailExchange' property is only set for MX records.

Example:

Set objDnsServer = CreateObject ( "ActiveXperts.DnsServer")     ' Create a new DnsServer 
                                                                ' instance
Set objConstants = CreateObject ( "ActiveXperts.ASConstants")

objDnsServer.Server  = "ns1.interstroom.nl"                     ' Apply queries to DNS 
                                                                ' server ns1.interstroom.nl    
objDnsServer.Lookup "activexperts.com", _ 
  objConstants.asDNS_TYPE_MX                                    ' Lookup MX records for 
                                                                ' activexperts.com    
If( objDnsServer.LastError = 0 ) Then
    WScript.Quit
End If
Set objDnsRecord = objDnsServer.GetFirstRecord                  ' Get first DNS record 
If( objDnsServer.LastError = 0 ) Then
    WScript.Echo "Name: " & objDnsRecord.Name
    WScript.Echo "MailExchange: " & objDnsRecord.MailExchange
    WScript.Echo "Preference: " & objDnsRecord.Preference
End If

Preference property

Type:

Number

Description:

MX preference. An MX-record has a "Preference" number indicating the order in which the mail server should be used. (Only relevant when multiple MX-records are defined for the same domain name). Mail servers will attempt to deliver mail to the server with the lowest preference number first, and if unsuccessful continue with the next lowest and so on.
The 'Preference' property is only set for MX records.

Example:

Set objDnsServer = CreateObject ( "ActiveXperts.DnsServer")     ' Create a new DnsServer 
                                                                ' instance
Set objConstants = CreateObject ( "ActiveXperts.ASConstants")

objDnsServer.Server  = "ns1.interstroom.nl"                     ' Apply queries to DNS 
                                                                ' server ns1.interstroom.nl    
objDnsServer.Lookup "activexperts.com", _ 
  objConstants.asDNS_TYPE_MX                                    ' Lookup MX records for 
                                                                ' activexperts.com    
If( objDnsServer.LastError = 0 ) Then
    WScript.Quit
End If
Set objDnsRecord = objDnsServer.GetFirstRecord                  ' Get first DNS record 
If( objDnsServer.LastError = 0 ) Then
    WScript.Echo "Name: " & objDnsRecord.Name
    WScript.Echo "MailExchange: " & objDnsRecord.MailExchange
    WScript.Echo "Preference: " & objDnsRecord.Preference
End If

NameServer property

Type:

String

Description:

The domain name of the primary DNS server for the zone. Only applies to SOA (Start of Authority) records.

Example:

Set objDnsServer = CreateObject ( "ActiveXperts.DnsServer")     ' Create a new DnsServer 
                                                                ' instance
Set objConstants = CreateObject ( "ActiveXperts.ASConstants")

objDnsServer.Server  = "ns1.interstroom.nl"                     ' Apply queries to DNS 
                                                                ' server ns1.interstroom.nl    
objDnsServer.Lookup "activexperts.com", _ 
  objConstants.asDNS_TYPE_SOA                                   ' Lookup SOA record 
                                                                ' for activexperts.com    
If( objDnsServer.LastError = 0 ) Then
    WScript.Quit
End If
Set objDnsRecord = objDnsServer.GetFirstRecord                  ' Get first DNS record 
If( objDnsServer.LastError = 0 ) Then                                
    WScript.Echo "Name: " & objDnsRecord.Name                   ' Display all SOA record 
                                                                ' fields 
    WScript.Echo "NameServer: " & objDnsRecord.NameServer
    WScript.Echo "MailBox: " & objDnsRecord.MailBox
    WScript.Echo "NameServer: " & objDnsRecord.NameServer
    WScript.Echo "SerialNumber: " & objDnsRecord.SerialNumber
    WScript.Echo "RefreshInterval: " & objDnsRecord.RefreshInterval
    WScript.Echo "RetryInterval: " & objDnsRecord.RetryInterval
    WScript.Echo "ExpirationLimit: " & objDnsRecord.ExpirationLimit
    WScript.Echo "MinimumTTL: " & objDnsRecord.MinimumTTL
End If

MailBox property

Type:

String

Description:

The email address (replace @ with a dot) of the person responsible for maintenance of the zone. The standard for this is the "hostmaster" username - such as "hostmaster.activexperts.com" (= hostmaster@activexperts.com). Only applies to SOA (Start of Authority) records.

Example:

Set objDnsServer = CreateObject ( "ActiveXperts.DnsServer")     ' Create a new DnsServer 
                                                                ' instance
Set objConstants = CreateObject ( "ActiveXperts.ASConstants")

objDnsServer.Server  = "ns1.interstroom.nl"                     ' Apply queries to DNS server 
                                                                ' ns1.interstroom.nl    
objDnsServer.Lookup "activexperts.com", ? 
  objConstants.asDNS_TYPE_SOA                                   ' Lookup SOA record 
                                                                ' for activexperts.com    
If( objDnsServer.LastError = 0 ) Then
    WScript.Quit
End If
Set objDnsRecord = objDnsServer.GetFirstRecord                  ' Get first DNS record 
If( objDnsServer.LastError = 0 ) Then                                
    WScript.Echo "Name: " & objDnsRecord.Name                   ' Display all SOA 
                                                                ' record fields 
    WScript.Echo "NameServer: " & objDnsRecord.NameServer
    WScript.Echo "MailBox: " & objDnsRecord.MailBox
    WScript.Echo "NameServer: " & objDnsRecord.NameServer
    WScript.Echo "SerialNumber: " & objDnsRecord.SerialNumber
    WScript.Echo "RefreshInterval: " & objDnsRecord.RefreshInterval
    WScript.Echo "RetryInterval: " & objDnsRecord.RetryInterval
    WScript.Echo "ExpirationLimit: " & objDnsRecord.ExpirationLimit
    WScript.Echo "MinimumTTL: " & objDnsRecord.MinimumTTL
End If

SerialNumber property

Type:

String

Description:

Used by secondary DNS servers to check if the zone has changed. If the serial number is higher than what the secondary server has, a zone transfer will be initiated. Only applies to SOA (Start of Authority) records.

Example:

Set objDnsServer = CreateObject ( "ActiveXperts.DnsServer")     ' Create a new 
                                                                ' DnsServer instance
Set objConstants = CreateObject ( "ActiveXperts.ASConstants")

objDnsServer.Server  = "ns1.interstroom.nl"                     ' Apply queries to DNS 
                                                                ' server ns1.interstroom.nl    
objDnsServer.Lookup "activexperts.com", _
  objConstants.asDNS_TYPE_SOA                                   ' Lookup SOA record 
                                                                ' for activexperts.com    
If( objDnsServer.LastError = 0 ) Then
    WScript.Quit
End If
Set objDnsRecord = objDnsServer.GetFirstRecord                  ' Get first DNS record 
If( objDnsServer.LastError = 0 ) Then                                
    WScript.Echo "Name: " & objDnsRecord.Name                   ' Display all SOA record 
                                                                ' fields 
    WScript.Echo "NameServer: " & objDnsRecord.NameServer
    WScript.Echo "MailBox: " & objDnsRecord.MailBox
    WScript.Echo "NameServer: " & objDnsRecord.NameServer
    WScript.Echo "SerialNumber: " & objDnsRecord.SerialNumber
    WScript.Echo "RefreshInterval: " & objDnsRecord.RefreshInterval
    WScript.Echo "RetryInterval: " & objDnsRecord.RetryInterval
    WScript.Echo "ExpirationLimit: " & objDnsRecord.ExpirationLimit
    WScript.Echo "MinimumTTL: " & objDnsRecord.MinimumTTL
End If

RefreshInterval property

Type:

Number

Description:

How often secondary DNS servers should check if changes are made to the zone. Only applies to SOA (Start of Authority) records.

Example:

Set objDnsServer = CreateObject ( "ActiveXperts.DnsServer")     ' Create a new 
                                                                ' DnsServer instance
Set objConstants = CreateObject ( "ActiveXperts.ASConstants")

objDnsServer.Server  = "ns1.interstroom.nl"                     ' Apply queries to DNS 
                                                                ' server ns1.interstroom.nl    
objDnsServer.Lookup "activexperts.com", _
  objConstants.asDNS_TYPE_SOA                                   ' Lookup SOA record 
                                                                ' for activexperts.com    
If( objDnsServer.LastError = 0 ) Then
    WScript.Quit
End If
Set objDnsRecord = objDnsServer.GetFirstRecord                  ' Get first DNS record 
If( objDnsServer.LastError = 0 ) Then                                
    WScript.Echo "Name: " & objDnsRecord.Name                   ' Display all SOA record 
                                                                ' fields 
    WScript.Echo "NameServer: " & objDnsRecord.NameServer
    WScript.Echo "MailBox: " & objDnsRecord.MailBox
    WScript.Echo "NameServer: " & objDnsRecord.NameServer
    WScript.Echo "SerialNumber: " & objDnsRecord.SerialNumber
    WScript.Echo "RefreshInterval: " & objDnsRecord.RefreshInterval
    WScript.Echo "RetryInterval: " & objDnsRecord.RetryInterval
    WScript.Echo "ExpirationLimit: " & objDnsRecord.ExpirationLimit
    WScript.Echo "MinimumTTL: " & objDnsRecord.MinimumTTL
End If

RetryInterval property

Type:

Number

Description:

How often secondary DNS server should retry checking if changes are made - if the first refresh fails. Only applies to SOA (Start of Authority) records.

Example:

Set objDnsServer = CreateObject ( "ActiveXperts.DnsServer")     ' Create a new DnsServer 
                                                                ' instance
Set objConstants = CreateObject ( "ActiveXperts.ASConstants")

objDnsServer.Server  = "ns1.interstroom.nl"                     ' Apply queries to DNS 
                                                                ' server ns1.interstroom.nl    
objDnsServer.Lookup "activexperts.com", _ 
  objConstants.asDNS_TYPE_SOA                                   ' Lookup SOA record for 
                                                                ' activexperts.com    
If( objDnsServer.LastError = 0 ) Then
    WScript.Quit
End If
Set objDnsRecord = objDnsServer.GetFirstRecord                  ' Get first DNS record 
If( objDnsServer.LastError = 0 ) Then                                
    WScript.Echo "Name: " & objDnsRecord.Name                   ' Display all SOA record 
                                                                ' fields 
    WScript.Echo "NameServer: " & objDnsRecord.NameServer
    WScript.Echo "MailBox: " & objDnsRecord.MailBox
    WScript.Echo "NameServer: " & objDnsRecord.NameServer
    WScript.Echo "SerialNumber: " & objDnsRecord.SerialNumber
    WScript.Echo "RefreshInterval: " & objDnsRecord.RefreshInterval
    WScript.Echo "RetryInterval: " & objDnsRecord.RetryInterval
    WScript.Echo "ExpirationLimit: " & objDnsRecord.ExpirationLimit
    WScript.Echo "MinimumTTL: " & objDnsRecord.MinimumTTL
End If

ExpirationLimit property

Type:

Number

Description:

How long the zone will be valid after a refresh. Secondary servers will discard the zone if no refresh could be made within this interval. Only applies to SOA (Start of Authority) records.

Example:

Set objDnsServer = CreateObject ( "ActiveXperts.DnsServer")     ' Create a new DnsServer 
                                                                ' instance
Set objConstants = CreateObject ( "ActiveXperts.ASConstants")

objDnsServer.Server  = "ns1.interstroom.nl"                     ' Apply queries to DNS 
                                                                ' server ns1.interstroom.nl    
objDnsServer.Lookup "activexperts.com", _ 
  objConstants.asDNS_TYPE_SOA                                   ' Lookup SOA record for 
                                                                ' activexperts.com    
If( objDnsServer.LastError = 0 ) Then
    WScript.Quit
End If
Set objDnsRecord = objDnsServer.GetFirstRecord                  ' Get first DNS record 
If( objDnsServer.LastError = 0 ) Then                                
    WScript.Echo "Name: " & objDnsRecord.Name                   ' Display all SOA record 
                                                                ' fields 
    WScript.Echo "NameServer: " & objDnsRecord.NameServer
    WScript.Echo "MailBox: " & objDnsRecord.MailBox
    WScript.Echo "NameServer: " & objDnsRecord.NameServer
    WScript.Echo "SerialNumber: " & objDnsRecord.SerialNumber
    WScript.Echo "RefreshInterval: " & objDnsRecord.RefreshInterval
    WScript.Echo "RetryInterval: " & objDnsRecord.RetryInterval
    WScript.Echo "ExpirationLimit: " & objDnsRecord.ExpirationLimit
    WScript.Echo "MinimumTTL: " & objDnsRecord.MinimumTTL
End If

MinimumTTL property

Type:

Number

Description:

Minimum (default) TTL. Only applies to SOA (Start of Authority) records.

Example:

Set objDnsServer = CreateObject ( "ActiveXperts.DnsServer")     ' Create a new DnsServer 
                                                                ' instance
Set objConstants = CreateObject ( "ActiveXperts.ASConstants")

objDnsServer.Server  = "ns1.interstroom.nl"                     ' Apply queries to DNS 
                                                                ' server ns1.interstroom.nl    
objDnsServer.Lookup "activexperts.com", _
  objConstants.asDNS_TYPE_SOA                                   ' Lookup SOA record for 
                                                                ' activexperts.com    
If( objDnsServer.LastError = 0 ) Then
    WScript.Quit
End If
Set objDnsRecord = objDnsServer.GetFirstRecord                  ' Get first DNS record 
If( objDnsServer.LastError = 0 ) Then                                
    WScript.Echo "Name: " & objDnsRecord.Name                   ' Display all SOA record 
                                                                ' fields 
    WScript.Echo "NameServer: " & objDnsRecord.NameServer
    WScript.Echo "MailBox: " & objDnsRecord.MailBox
    WScript.Echo "NameServer: " & objDnsRecord.NameServer
    WScript.Echo "SerialNumber: " & objDnsRecord.SerialNumber
    WScript.Echo "RefreshInterval: " & objDnsRecord.RefreshInterval
    WScript.Echo "RetryInterval: " & objDnsRecord.RetryInterval
    WScript.Echo "ExpirationLimit: " & objDnsRecord.ExpirationLimit
    WScript.Echo "MinimumTTL: " & objDnsRecord.MinimumTTL
End If

5.3. Functions

Functions

Function Description
Clear Reset all properties to their default values
GetErrorDescription Get the description of the given error

Clear function

Description:

Resets all properties to the initial, default values.

Parameters:

  • None

Return value:

Always 0.

Example:

Set objDnsServer = CreateObject ( "ActiveXperts.DnsServer")     ' Create a new DnsServer 
                                                                ' instance
Set objConstants = CreateObject ( "ActiveXperts.ASConstants")

objDnsServer.Server  = "ns1.interstroom.nl"                     ' Apply queries to DNS server 
                                                                ' ns1.interstroom.nl    
objDnsServer.Lookup "activexperts.com", _ 
  objConstants.asDNS_TYPE_ANY                                   ' Lookup any record for 
                                                                ' activexperts.com    
If( objDnsServer.LastError = 0 ) Then
    WScript.Quit
End If
Set objDnsRecord = objDnsServer.GetFirstRecord                  ' Get first DNS record 
While( objDnsServer.LastError = 0 ) Then                                
    WScript.Echo "Name: " & objDnsRecord.Name                       
    objDnsRecord.Clear()                                        ' Clear DNS record 
    Set objDnsRecord = objDnsServer.GetNextRecord               ' Get next DNS record 
WEnd

GetErrorDescription function

Description:

GetErrorDescription provides the error description of a given error code.

Parameters:

  • Error code.

Return value:

The error description that is associated with the given error code.

Example:

Set objDnsServer = CreateObject ( "ActiveXperts.DnsServer")     ' Create a new DnsServer 
                                                                ' instance
Set objConstants = CreateObject ( "ActiveXperts.ASConstants")

objDnsServer.Server  = "ns1.interstroom.nl"                            
objDnsServer.Lookup "activexperts.com", objConstants.asDNS_TYPE_ANY   
WScript.Echo "LastError: " & objDnsServer.LastError
WScript.Echo "Error description: " & objDnsServer.GetErrorDescription( objDnsServer.LastError )
...

6. DnsRecord

6.1. Introduction

DNS is the Domain Name System. DNS converts machine names to the IP addresses that all machines on the net have. It translates (i.e. 'maps') from name to address and from address to name, and some other things.

The ActiveSocket DNS objects can be used to query servers running a domain name service (DNS) application. It will send domain name query packets to any designated DNS server. There are three data elements required in order to formulate a DNS query using ActiveSocket:

  • DNS servername/address
  • Internet style address that is being queried
  • Type of record you are searching for

The ActiveSocket DNS objects are useful for gathering address information about hosts in the network. It can be used to query DNS for specific information about hosts, like mail exchanger records [MX], IP address [A], canonical names [CNAME], etc. If you have an IP address, you can get a canonical name back for the address and vice versa. Another useful feature is the ability to get a listing of hosts which serve mail exchange [MX] functions for a specific domain.

The following sample (VBScript) shows how the DnsServer and DnsRecord objects can be used to list all DNS records for a specific domain name:

    
Set objDnsServer = CreateObject ( "ActiveXperts.DnsServer")     ' Create object
Set objConstants = CreateObject ( "ActiveXperts.ASConstants")

objDnsServer.Host       = "ns1.interstroom.nl"                  ' DNS server
       
objDnsServer.Lookup "activexperts.com", _
  objConstants.asDNS_TYPE_ANY                                   ' Show all DNS records 
                                                                ' for activexperts.com
WScript.Echo "Lookup, result: " & objDnsServer.LastError    
If( objDnsServer.LastError <> 0 ) Then
    WScript.Quit
End If

If ( objDnsServer.IsAuthoritative = True ) Then
    WScript.Echo "Server is an authority for this domain"
Else
    WScript.Echo "Server is not an authority for this domain"
End If
    
Set objDnsRecord = objDnsServer.GetFirstRecord                  ' Iterate over all DNS 
                                                                ' records; get first record   	
While ( objDnsServer.LastError = 0 )
    Select Case objDnsRecord.Type 
      Case objConstants.asDNS_TYPE_A
        WScript.Echo "Type             : A"
        WScript.Echo "Name             : " & objDnsRecord.Name
        WScript.Echo "IPv4 Address     : " & objDnsRecord.Address
      Case objConstants.asDNS_TYPE_AAAA
        WScript.Echo "Type             : AAAA"
        WScript.Echo "Name             : " & objDnsRecord.Name
        WScript.Echo "IPv6 Address     : " & objDnsRecord.Address
      Case objConstants.asDNS_TYPE_CNAME
        WScript.Echo "Type             : CNAME"
        WScript.Echo "Name             : " & objDnsRecord.Name
        WScript.Echo "Alias            : " & objDnsRecord.Address
      Case objConstants.asDNS_TYPE_MX 
        WScript.Echo "Type             : MX"
        WScript.Echo "Name             : " & objDnsRecord.Name
        WScript.Echo "Preference       : " & objDnsRecord.Preference
        WScript.Echo "Mail Exchange    : " & objDnsRecord.MailExchange
      Case objConstants.asDNS_TYPE_NS
        WScript.Echo "Type             : NS"
        WScript.Echo "Name             : " & objDnsRecord.Name
        WScript.Echo "Name Server      : " & objDnsRecord.NameServer
      Case objConstants.asDNS_TYPE_PTR
        WScript.Echo "Type             : PTR"
        WScript.Echo "Name             : " & objDnsRecord.Name
        WScript.Echo "Host             : " & objDnsRecord.Address
      Case objConstants.asDNS_TYPE_SOA
        WScript.Echo "Type             : SOA"
        WScript.Echo "Name             : " & objDnsRecord.Name
        WScript.Echo "Name Server      : " & objDnsRecord.NameServer
        WScript.Echo "MailBox          : " & objDnsRecord.MailBox
        WScript.Echo "Serial           : " & objDnsRecord.SerialNumber
        WScript.Echo "Refresh          : " & objDnsRecord.RefreshInterval
        WScript.Echo "Retry Interval   : " & objDnsRecord.RetryInterval
        WScript.Echo "Expiration Limit : " & objDnsRecord.ExpirationLimit
        WScript.Echo "Minimum TTL      : " & objDnsRecord.MinimumTTL
    End Select
  
    WScript.Echo "TTL              : " & objDnsRecord.TTL
    WScript.Echo
    
    Set objDnsRecord = objDnsServer.GetNextRecord               ' Iterate over all DNS 
                                                                ' records; get next record
Wend

6.2. Properties

Properties

Property Type Read/Write Description
Version String Out Version number of ActiveSocket
Build String Out Display build information of ActiveSocket
ExpirationDate String Out Expiration date of ActiveSocket
Server String In/Out Remote DNS Server's host name or IP address
ServerPort Number In/Out DNS Server port. Default: 53
LastError Number Out Result of the last called function
LogFile String In/Out Log file that can be used for troubleshooting purposes

Version property

Type:

String

Description:

Version information of ActiveSocket. This property is read-only; you cannot assign a value to it.

Example:

Set objDnsServer = CreateObject("ActiveXperts.DnsServer")       ' Create a new DnsServer 
                                                                ' instance
WScript.Echo  "Version: " & objDnsServer.Version

Build property

Type:

String

Description:

Build information of ActiveSocket. This property is read-only; you cannot assign a value to it.

Example:

Set objDnsServer = CreateObject( "ActiveXperts.DnsServer" )     ' Create a new DnsServer 
                                                                ' object
WScript.Echo  "Build: " & objDnsServer.Build

ExpirationDate property

Type:

String

Description:

Expiration date of ActiveSocket. This property is read-only; you cannot assign a value to it.
Once you have registered the product, the property holds the empty string ("") value.

Example:

Set objDnsServer = CreateObject( "ActiveXperts.DnsServer" )     ' Create a new DnsServer 
                                                                ' instance
WScript.Echo "ExpirationDate: " & objDnsServer.ExpirationDate

Server property

Type:

String

Description:

Host name or IP address of the DNS server.

Example:

Set objDnsServer = CreateObject ( "ActiveXperts.DnsServer")     ' Create a new DnsServer 
                                                                ' instance
Set objConstants = CreateObject ( "ActiveXperts.ASConstants")

objDnsServer.Server      = "ns1.xyz.intra"                      ' Remote DNS server: 
                                                                ' ns1.xyz.intra    
objDnsServer.Lookup "activexperts.com", _ 
  objConstants.asDNS_TYPE_ANY                                   ' Lookup any record for 
                                                                ' activexperts.com    
...

ServerPort property

Type:

Number

Description:

TCP port number to identify a (remote) DNS server. If you don't specify the 'ServerPort' property, port 53 (default DNS port) is used.

Example:

Set objDnsServer = CreateObject ( "ActiveXperts.DnsServer")     ' Create a new DnsServer
                                                                ' instance
Set objConstants = CreateObject ( "ActiveXperts.ASConstants")

objDnsServer.Server      = "ns1.xyz.intra"                      ' Remote DNS server:
                                                                ' ns1.xyz.intra    
objDnsServer.ServerPort  = 8053                                 ' Use alternate port:8053    
objDnsServer.Lookup "activexperts.com", _
  objConstants.asDNS_TYPE_ANY                                   ' Lookup any record for
                                                                ' activexperts.com    
...

LastError property

Type:

Number

Description:

The result of a previous called function. Use it to check the result of your last function call. A zero indicates: success. Any non-zero value means an error.
The GetErrorDescription function provides the error description of an error code.
For a complete list of error codes, check out the following page: www.activexperts.com/support/errorcodes.

Example:

Set objDnsServer = CreateObject ( "ActiveXperts.DnsServer")     ' Create a new 
                                                                ' DnsServer instance
Set objConstants = CreateObject ( "ActiveXperts.ASConstants")

objDnsServer.Server  = "ns1.interstroom.nl"                     ' Apply queries to DNS 
                                                                ' server ns1.interstroom.nl    
objDnsServer.Lookup "activexperts.com", _
  objConstants.asDNS_TYPE_ANY                                   ' Lookup any record for 
                                                                ' activexperts.com    
WScript.Echo "Lookup, result: " & objDnsServer.LastError        ' Show result

LogFile property

Type:

String

Description:

For troubleshooting purposes, you can specify a log file to trace all DNS operations. By default, the 'LogFile' property holds the empty string. By assigning a valid filename to it, all DNS operations will be written to this log file.

Example:

Set objDnsServer = CreateObject ( "ActiveXperts.DnsServer")     ' Create a new DnsServer
                                                                ' instance
Set objConstants = CreateObject ( "ActiveXperts.ASConstants")

objDnsServer.LogFile = "c:\dns.log"                             ' Set log file    
objDnsServer.Server  = "ns1.interstroom.nl"                          
objDnsServer.Lookup "activexperts.com", objConstants.asDNS_TYPE_ANY  
... 

6.3. Functions

Functions

Function Description
Clear Reset all properties to their default values
Lookup Lookup DNS record(s)
GetNextRecord Get next DNS record
IsAuthoritative Set to True if DNS server is authoritative
GetErrorDescription Get the description of the given error
Sleep Suspends the execution of the object for at least the specified interval
Activate Activate Software

Clear function

Description:

Resets all properties to the initial, default values.

Parameters:

  • None

Return value:

Always 0.

Example:

Set objDnsServer = CreateObject ( "ActiveXperts.DnsServer")     ' Create a new DnsServer 
                                                                ' instance
Set objConstants = CreateObject ( "ActiveXperts.ASConstants")

objDnsServer.Server      = "ns1.xyz.intra"                      ' Remote DNS server: 
                                                                ' ns1.xyz.intra    
objDnsServer.Lookup "activexperts.com", _
  objConstants.asDNS_TYPE_ANY                                   ' Lookup any record for 
                                                                ' activexperts.com    
...
objDnsServer.Clear                                              ' Reset all properties  
objDnsServer.Server      = "ns1.interstroom.nl"                 ' Remote DNS server: 
                                                                ' ns1.xyz.intra    
...

Lookup function

Description:

Lookup DNS record(s).

Parameters:

  • The hostname or IP address of the (remote) DNS server server
  • Type of DNS record(s) to lookup. Click here for a list of valid DNS types. Specify asDNS_TYPE_ANY to query for any type.

Return value:

Always 0. Check LastError property to see if the function was completed successfully.

Example:

Set objDnsServer = CreateObject ( "ActiveXperts.DnsServer")     ' Create a new DnsServer 
                                                                ' instance
Set objConstants = CreateObject ( "ActiveXperts.ASConstants")

objDnsServer.Server  = "ns1.interstroom.nl"                     ' Apply queries to DNS server 
                                                                ' ns1.interstroom.nl    
objDnsServer.Lookup "activexperts.com", _
  objConstants.asDNS_TYPE_ANY                                   ' Lookup any dns record for 
                                                                ' activexperts.com    
If( objDnsServer.LastError = 0 ) Then
    WScript.Quit
End If
Set objDnsRecord = objDnsServer.GetFirstRecord                  ' Get first DNS record 
...

GetNextRecord function

Description:

Iterate over all DSN records that were a result of the Lookup query.

Parameters:

  • None

Return value:

Always 0. Check LastError property to see if the function was completed successfully.

Example:

Set objDnsServer = CreateObject ( "ActiveXperts.DnsRecord")     ' Create a new DnsRecord 
                                                                ' instance
Set objConstants = CreateObject ( "ActiveXperts.ASConstants")

objDnsServer.Server  = "ns1.interstroom.nl"                     ' Apply queries to DNS server 
                                                                ' ns1.interstroom.nl    
objDnsServer.Lookup "activexperts.com", _
  objConstants.asDNS_TYPE_ANY                                   ' Lookup any dns record for 
                                                                ' activexperts.com    
If( objDnsServer.LastError = 0 ) Then
    WScript.Quit
End If
Set objDnsRecord = objDnsServer.GetFirstRecord                  ' Get first DNS record 
While( objDnsServer.LastError = 0 )
    WScript.Echo "Name: " & objDnsRecord.Name
    ...
    Set objDnsRecord = objDnsServer.GetNextRecord               ' Get next DNS record 
WEnd

IsAuthoritative function

Description:

Indicates if DNS server is authoritative for the queried domain.

Parameters:

  • True of False.

Return value:

Always 0. Check LastError property to see if the function was completed successfully.

Example:

Set objDnsServer = CreateObject ( "ActiveXperts.DnsRecord")     ' Create a new DnsRecord 
                                                                ' instance
Set objConstants = CreateObject ( "ActiveXperts.ASConstants")

objDnsServer.Server  = "ns1.interstroom.nl"                     ' Apply queries to DNS server 
                                                                ' ns1.interstroom.nl    
objDnsServer.Lookup "activexperts.com", _
  objConstants.asDNS_TYPE_ANY                                   ' Lookup any dns record for 
                                                                ' activexperts.com    
If( objDnsServer.LastError = 0 ) Then
    WScript.Quit
End If
WScript.Echo "IsAuthoritative: " & _ 
  objDnsServer.IsAuthoritative()                                ' Is authoritative ?

GetErrorDescription function

Description:

GetErrorDescription provides the error description of a given error code.

Parameters:

  • Error code.

Return value:

The error description that is associated with the given error code.

Example:

Set objDnsServer = CreateObject ( "ActiveXperts.DnsRecord")     ' Create a new DnsRecord 
                                                                ' instance
Set objConstants = CreateObject ( "ActiveXperts.ASConstants")

objDnsServer.Server  = "ns1.interstroom.nl"                            
objDnsServer.Lookup "activexperts.com", objConstants.asDNS_TYPE_ANY   
WScript.Echo "LastError: " & objDnsServer.LastError
WScript.Echo "Error description: " & objDnsServer.GetErrorDescription( objDnsServer.LastError )
...

Sleep function

Description:

This function can be used in your script anywhere you want; Suspends the execution of the object for at least the specified interval.

Parameters:

  • The number of milliseconds to hold.

Return value:

Always 0.

Example:

Set objDnsServer   = CreateObject( "ActiveXperts.DnsRecord" )   ' Create DnsRecord object
Set objConstants   = CreateObject( "ActiveXperts.ASConstants" ) ' Create constants object
...
objDnsServer.Sleep 500

Activate function

Description:

This function activates the ActiveSocket product. A valid registration code is required.

Parameters:

  • The registration key
  • Persistent - this optional Boolean variable (default: True) specifies whether you want to add the registration key to the registry.
    If you pass 'True', you need to call the 'Activate' function only once for that computer.
    If you pass 'False', you need to call 'Activate' each time you create the object on that computer. This can be useful for customers who own a Distribution License of the product but do not want to show the registration key to their customers (see also here)

Return value:

Always 0. Check LastError property to see if the function was completed successfully.

Example:

Set objDnsServer = CreateObject( "ActiveXperts.DnsRecord" )     ' Create DnsRecord object
objDnsServer.Activate "xyz", True                               ' Substitute xyz by your 
                                                                ' own registrationkey
' Pass True to make the activation persistent, so you need to call
' Activate only once. If you pass 
' False, you need to call 
' Activate each time the product is started.

7. FtpServer

7.1. Introduction

FTP stands for File Transfer Protocol: a communication standard which allows computers to transfer files back and forth in spite of differences in how different operating systems handle file names, directories and file formats.

The local (client) computer is the one you're directly connected to, and the remote (server) computer is the one that you want to get files from or put files to. You need to specify the Internet address of the remote computer, e.g. ftp.activexperts-labs.com.

Some sites maintain archives of files for public use, permitting access using the username anonymous. Usually you are asked to enter your real e-mail address as the password. If a site is not using anonymous FTP, you must provide the username and password which has been assigned to you for that computer.

FTP programmes have different methods of handling plain-text files and binary files. The plain-text mode attempts to correct for the different ways that different operating systems handle line breaks in text files, while the binary mode ensures that all of the special non-printing bytes are transferred without change. HTML files are plain-text files, while word-processing documents and images are binary files.

The following sample (VBScript) shows how the FtpServer and FtpFile objects can be used to list files in a specific directory on an FTP server:

Set objFtpServer = CreateObject ( "ActiveXperts.FtpServer" )

objFtpServer.Connect "ftp.activexperts-labs.com","anonymous","" ' Connect to the FTP server 
                                                                ' using the anonymous account 
Wscript.Echo "Connect, result: " & objFtpServer.LastError
If( objFtpServer.LastError <> 0 ) Then                          ' If connect failed then quit
   WScript.Quit
End If

objFtpServer.ChangeDir "samples/network-component/Visual Basic/Telnet"    ' Change directory
Wscript.Echo "ChangeDir, result: " & _
 objFtpServer.LastError
If( objFtpServer.LastError <> 0 ) Then                          ' If ChangeDir fails then 
                                                                ' disconnect and quit
   objFtpServer.Disconnect
   WScript.Quit
End If

Set objFtpFile = objFtpServer.FindFirstFile()                   ' Iterate over all files in dir 
                                                                ' Start with first file
While( objFtpServer.LastError = 0 )
   WScript.Echo "Name: " & objFtpFile.Name                      ' Display file name
   WScript.Echo "IsDirectory: " & objFtpFile.IsDirectory        ' Display directory or file
   WScript.Echo "Size: " & objFtpFile.Size                      ' Display file size
   WScript.Echo "Date: " & objFtpFile.Date                      ' Display file date
    
   ' To save the file, call the GetFile function. 
   ' strSaveAs = "C:\temp\" & objFtpFile.Name
   ' objFtpServer.GetFile objFtpFile.Name, strSaveAs
   ' Wscript.Echo "Save file, result: " & objFtpServer.LastError

   ' To delete a file, call the DeleteFile function. 
   ' objFtpServer.DeleteFile objFtpFile.Name
   ' Wscript.Echo "Delete, result: " & objFtpServer.LastError

   Set objFtpFile = objFtpServer.FindNextFile()                 ' Next file
Wend

objFtpServer.Disconnect                                         ' Disconnect

7.2. Properties

Properties

Property Type Read/Write Description
Version String Out Version number of ActiveSocket
Build String Out Display build information of ActiveSocket
ExpirationDate String Out Expiration date of ActiveSocket
HostPort Number In/Out TCP port of the remote FTP server. Default: 21
PassiveMode Boolean In/Out Specifies how to connect: passive (default) or active
BinaryTransfer Boolean In/Out Specifies how to transfer files: binary (default) or ASCII
LastError Number Out Result of the last called function
LastResponse String Out Last response from FTP server
LogFile String In/Out Log file for troubleshooting purposes

Version property

Type:

String

Description:

Version information of ActiveSocket. This property is read-only; you cannot assign a value to it.

Example:

Set objFtpServer = CreateObject("ActiveXperts.FtpServer")       ' Create a new FtpServer 
                                                                ' instance
WScript.Echo  "Version: " & objFtpServer.Version

Build property

Type:

String

Description:

Build information of ActiveSocket. This property is read-only; you cannot assign a value to it.

Example:

Set objFtpServer = CreateObject( "ActiveXperts.FtpServer" )     ' Create a new FtpServer 
                                                                ' object
WScript.Echo  "Build: " & objFtpServer.Build

ExpirationDate property

Type:

String

Description:

Expiration date of ActiveSocket. This property is read-only; you cannot assign a value to it.
Once you have registered the product, the property holds the empty string ("") value.

Example:

Set objFtpServer = CreateObject( "ActiveXperts.FtpServer" )     ' Create a new FtpServer 
                                                                ' instance
WScript.Echo "ExpirationDate: " & objFtpServer.ExpirationDate

HostPort property

Type:

Number

Description:

TCP port number to identify a (remote) FTP server. If you don't specify the 'HostPort' property, port 21 (default FTP port) is used.

Example:

Set objFtpServer = CreateObject( "ActiveXperts.FtpServer" )     ' Create a new FtpServer 
                                                                ' instance
...
objFtpServer.HostPort = 8021                                    ' Use port 8021 instead 
                                                                ' of default port 21
objFtpServer.Connect "ftpserver1", "account", "pwd"             ' Connect to host 
                                                                ' ftpserver1 on port 8021
...

PassiveMode property

Type:

Boolean

Description:

Specifies the way to connect to the remote FTP server: in Passive mode or in Active mode. Default value: True (Passive)

Example:

Set objFtpServer = CreateObject( "ActiveXperts.FtpServer" )     ' Create a new FtpServer 
                                                                ' instance
...
objFtpServer.PassiveMode = False                                ' Use Active mode instead 
                                                                ' of the default Passive mode
objFtpServer.Connect "ftpserver1", "account", "pwd"             ' Connect to host ftpserver1 
                                                                ' in Active mode
...

BinaryTransfer property

Type:

Boolean

Description:

Specifies the way files are transfered when downloading (GetFile) or uploading (PutFile) files. Default value: True, indicating that files are tranferred in binary mode by default.

Example:

Set objFtpServer = CreateObject( "ActiveXperts.FtpServer" )     ' Create a new FtpServer 
                                                                ' instance
...
objFtpServer.Connect "ftpserver1", "account", "pwd"             ' Connect to host ftpserver1
...
objFtpServer.BinaryMode = False                                 ' Files transfer in ASCII mode 
                                                                ' when using GetFile/PutFile
Set objFtpFile = objFtpServer.GetFile( "c:\temp\log1.txt", _
  "/logfiles/log1.txt" )                                        ' Download log1.txt in ASCII 
                                                                ' mode

LastError property

Type:

Number

Description:

The result of a previous called function. Use it to check the result of your last function call. A zero indicates: success. Any non-zero value means an error.
The GetErrorDescription function provides the error description of an error code.
For a complete list of error codes, check out the following page: www.activexperts.com/support/errorcodes.

Example:

Set objFtpServer = CreateObject( "ActiveXperts.FtpServer" )     ' Create a new FtpServer 
                                                                ' instance
...
objFtpServer.Connect "ftpserver1", "account", "pwd"             ' Connect to host ftpserver1
WScript.Echo "LastError: " & objFtpServer.LastError
...

LastResponse property

Type:

String

Description:

The last response of an FTP operation is stored in the 'LastResponse' property. It can be used for troubleshooting purposes.

Example:

Set objFtpServer = CreateObject( "ActiveXperts.FtpServer" )     ' Create a new FtpServer 
                                                                ' instance
...
objFtpServer.Connect "ftpserver1", "account", "pwd"             ' Connect to host ftpserver1
WScript.Echo "LastResponse: " & objFtpServer.LastResponse       ' Display the last response 
                                                                ' from the FTP server
...

LogFile property

Type:

String

Description:

For troubleshooting purposes, you can specify a log file to trace all FTP operations. By default, the 'LogFile' property holds the empty string. By assigning a valid filename to it, all FTP operations will be written to this log file.

Example:

Set objFtpServer = CreateObject( "ActiveXperts.FtpServer" )     ' Create a new FtpServer 
                                                                ' instance
objFtpServer.LogFile = "C:\Ftp.log"                             ' Write all FTP operations 
                                                                ' to the specified log file
...
objFtpServer.Connect "ftpserver1", "account", "pwd"             ' Connect to host ftpserver1
...

7.3. Functions

Functions

Function Description
Clear Reset all properties to their default values
Connect Connect to a remote FTP server
Disconnect Close the connection
GetCurrentDir Retrieve the current directory
ChangeDir Change directory
CreateDir Create directory
RenameDir Rename directory
DeleteDir Delete directory
FindFile Find a file in the current directory
FindFirstFile Find first file in the current directory
FindNextFile Find next file in the current directory
RenameFile Rename a file in the current directory
DeleteFile Delete a file in the current directory
GetFile Download (get) a file from the current directory
PutFile Upload (put) a file to the current directory
GetErrorDescription Get the description of the given error
Sleep Suspends the execution of the object for at least the specified interval
Activate Suspends the execution of the object for at least the specified interval

Clear function

Description:

Resets all properties to the initial, default values.

Parameters:

  • None

Return value:

Always 0.

Example:

' Create a new FtpServer instance
Set objFtpServer = CreateObject( "ActiveXperts.FtpServer" ) 
objFtpServer.Connect "ftpserver1", "account", "pwd"             ' Connect to host ftpserver1
...
objFtpServer.Disconnect                                         ' Disconnect
objFtpServer.Clear                                              ' Clear properties before 
                                                                ' connecting to another FTP 
                                                                ' server
objFtpServer.Connect "ftpserver2", "account", "pwd"             ' Connect to host ftpserver2

Connect function

Description:

Call this function to connect to a remote FTP server. By default, a Passive connection will be established. If you want to establish a connection in Active mode, you should set the PassiveMode flag to False.

Parameters:

  • The hostname or IP address of the remote server
  • The FTP account; use 'anonymous' for anonymous login
  • The FTP password; use an e-mail address for anonymous login

Return value:

Always 0. Check LastError property to see if the function was completed successfully.

Example:

Set objFtpServer = CreateObject( "ActiveXperts.FtpServer" )     ' Create a new FtpServer 
                                                                ' instance
objFtpServer.Connect "ftpserver1", "account", "pwd"             ' Connect to host ftpserver1
If( objFtpServer.LastError = 0 ) Then
   ...
   objFtpServer.ChangeDir( "/pictures" )
   ...
   objFtpServer.Disconnect
End If

Disconnect function

Description:

Call this function to close a connnection that was established using the Connect function.

Parameters:

  • None

Return value:

Always 0. Check LastError property to see if the function was completed successfully.

Example:

Set objFtpServer = CreateObject( "ActiveXperts.FtpServer" )     ' Create a new FtpServer 
                                                                ' instance
objFtpServer.Connect "ftpserver1", "account", "pwd"             ' Connect to host ftpserver1
If( objFtpServer.LastError = 0 ) Then
   ...
   objFtpServer.Disconnect                                      ' Close the session
End If

GetCurrentDir function

Description:

The directory string. If the function fails, an empty string is returned and the LastError property is set to a non-zero value indicating the reason for failing.

Parameters:

  • None

Return value:

Always 0. Check LastError property to see if the function was completed successfully.

Example:

Set objFtpServer = CreateObject( "ActiveXperts.FtpServer" )      ' Create a new FtpServer 
                                                                 ' instance
objFtpServer.Connect "ftpserver1", "account", "pwd"              ' Connect to host ftpserver1
If( objFtpServer.LastError = 0 ) Then
   ...
   strCurrentDir = objFtpServer.GetCurrentDir()                  ' Retrieve current directory
   If( objFtpServer.LastError = 0 ) Then
      WScript.Echo "Current Directory: " & strCurrentDir
   End If
   objFtpServer.Disconnect                                       ' Close the session
End If

ChangeDir function

Description:

Change the current directory on the remote FTP server. You can use a fully qualified directory name, or a plain directory name.

Parameters:

  • Directory name

Return value:

Always 0. Check LastError property to see if the function was completed successfully.

Example:

Set objFtpServer = CreateObject( "ActiveXperts.FtpServer" )     ' Create a new FtpServer 
                                                                ' instance
objFtpServer.Connect "ftpserver1", "account", "pwd"             ' Connect to host ftpserver1
If( objFtpServer.LastError = 0 ) Then
   ...
   objFtpServer.ChangeDir( "/pictures" )                        ' Change directory to: 
                                                                ' /pictures
   objFtpServer.ChangeDir( "family" )                           ' Change directory to: 
                                                                ' /pictures/family
   ...
   objFtpServer.ChangeDir( "/pictures/friends" )                ' Change directory to: 
                                                                ' /pictures/friends
   ...
   objFtpServer.Disconnect                                      ' Close the session
End If

CreateDir function

Description:

Create a new directory on the remote FTP server in the directory indicated by GetCurrentDir.

Parameters:

  • The directory to create. You can use a fully qualified directory name, or a plain directory name.

Return value:

Always 0. Check LastError property to see if the function was completed successfully.

Example:

Set objFtpServer = CreateObject( "ActiveXperts.FtpServer" )     ' Create a new FtpServer 
                                                                ' instance
objFtpServer.Connect "ftpserver1", "account", "pwd"             ' Connect to host ftpserver1
If( objFtpServer.LastError = 0 ) Then
   ...
   objFtpServer.ChangeDir( "/pictures" )                        ' Change directory to: 
                                                                ' /pictures
   objFtpServer.CreateDir( "family" )                           ' Create new directory 
                                                                ' 'family'
   ...
   objFtpServer.Disconnect                                      ' Close the session
End If

RenameDir function

Description:

Rename directory.

Parameters:

  • Name of the directory to rename
  • New name of the directory

Return value:

Always 0. Check LastError property to see if the function was completed successfully.

Example:

Set objFtpServer = CreateObject( "ActiveXperts.FtpServer" )     ' Create a new FtpServer 
                                                                ' instance
objFtpServer.Connect "ftpserver1", "account", "pwd"             ' Connect to host ftpserver1
If( objFtpServer.LastError = 0 ) Then
   ...
   objFtpServer.RenameDir( "pictures", "images" )               ' Rename directory 'pictures' 
                                                                ' into 'images'
   ...
   objFtpServer.Disconnect                                      ' Close the session
End If

DeleteDir function

Description:

Delete a directory.

Parameters:

  • The directory to delete. You can use a fully qualified directory name, or a plain directory name. Make sure that this directory is empty.

Return value:

Always 0. Check LastError property to see if the function was completed successfully.

Example:

Set objFtpServer = CreateObject( "ActiveXperts.FtpServer" )     ' Create a new FtpServer 
                                                                ' instance
objFtpServer.Connect "ftpserver1", "account", "pwd"             ' Connect to host ftpserver1
If( objFtpServer.LastError = 0 ) Then
   ...
   objFtpServer.ChangeDir( "/pictures" )                        ' Change directory to: 
                                                                ' /pictures
   objFtpServer.DeleteDir( "family" )                           ' Delete directory 'family'
   ...
   objFtpServer.Disconnect                                      ' Close the session
End If

FindFile function

Description:

Find a file. You can use a plain filename (the file will then be retrieved from the current directory) or you can use a fully qualified filename.

Parameters:

  • Filename

Return value:

Always 0. Check LastError property to see if the function was completed successfully.

Example:

Set objFtpServer = CreateObject( "ActiveXperts.FtpServer" )      ' Create a new FtpServer 
                                                                 ' instance
objFtpServer.Connect "ftpserver1", "account", "pwd"              ' Connect to host ftpserver1
If( objFtpServer.LastError = 0 ) Then
   Set objFtpFile1 = objFtpServer.FindFile( _
     "/pictures/picture1.jpg")                                   ' Find file using a fully 
                                                                 ' qualified filename
   ...
   objFtpServer.ChangeDir( "/pictures" )
   Set objFtpFile2 = objFtpServer.FindFile( "picture2.jpg")      ' Find file using a plain 
                                                                 ' filename
   objFtpServer.Disconnect                                       ' Close the session
End If

FindFirstFile function

Description:

Iterate of all files and directories in the current directory. The 'FindFirstFile' function retrieves the first file/directory. You can call 'FindNextFile' until there are no more files/directories.

Parameters:

  • None

Return value:

Always 0. Check LastError property to see if the function was completed successfully.

Example:

Set objFtpServer = CreateObject( "ActiveXperts.FtpServer" )     ' Create a new FtpServer 
                                                                ' instance
objFtpServer.Connect "ftpserver1", "account", "pwd"             ' Connect to host ftpserver1
If( objFtpServer.LastError = 0 ) Then
   Set objFtpFile = objFtpServer.FindFirstFile()
   While( objFtpServer.LastError = 0 )
       WScript.Echo "File: " & objFtpFile.Name                  ' Display filename 
                                                                ' (or directoryname)
       Set objFtpFile = objFtpServer.FindNextFile()
   WEnd
   objFtpServer.Disconnect                                      ' Close the session
End If

FindNextFile function

Description:

Iterate of all files and directories in the current directory. The 'FindFirstFile' function retrieves the first file/directory. You can call 'FindNextFile' until there are no more files/directories.

Parameters:

  • None

Return value:

Always 0. Check LastError property to see if the function was completed successfully.

Example:

Set objFtpServer = CreateObject( "ActiveXperts.FtpServer" )     ' Create a new FtpServer 
                                                                ' instance
objFtpServer.Connect "ftpserver1", "account", "pwd"             ' Connect to host ftpserver1
If( objFtpServer.LastError = 0 ) Then
   Set objFtpFile = objFtpServer.FindFirstFile()
   While( objFtpServer.LastError = 0 )
       WScript.Echo "File: " & objFtpFile.Name                  ' Display filename (or 
                                                                ' directoryname)
       Set objFtpFile = objFtpServer.FindNextFile()
   WEnd
   objFtpServer.Disconnect                                      ' Close the session
End If

RenameFile function

Description:

Rename file.

Parameters:

  • Name of the file to rename
  • New name of the file

Return value:

Always 0. Check LastError property to see if the function was completed successfully.

Example:

Set objFtpServer = CreateObject( "ActiveXperts.FtpServer" )     ' Create a new FtpServer 
                                                                ' instance
objFtpServer.Connect "ftpserver1", "account", "pwd"             ' Connect to host ftpserver1
If( objFtpServer.LastError = 0 ) Then
   ...
   objFtpServer.ChangeDir( "/pictures" )                        ' Change directory to: 
                                                                ' /pictures
   objFtpServer.Rename( "old.jpg", "new.jpg" )                  ' Rename 'old.jpg' into
                                                                ' 'new.jpg'
   ...
   objFtpServer.Disconnect                                      ' Close the session
End If

DeleteFile function

Description:

Delete file.

Parameters:

  • Name of the file to delete

Return value:

Always 0. Check LastError property to see if the function was completed successfully.

Example:

Set objFtpServer = CreateObject( "ActiveXperts.FtpServer" )     ' Create a new FtpServer 
                                                                ' instance
objFtpServer.Connect "ftpserver1", "account", "pwd"             ' Connect to host 
                                                                ' ftpserver1
If( objFtpServer.LastError = 0 ) Then
   ...
   objFtpServer.ChangeDir( "/pictures" )                        ' Change directory to: 
                                                                ' /pictures
   objFtpServer.Delete( "picture1.jpg" )                        ' Delete 'picture1.jpg'
   ...
   objFtpServer.Disconnect                                      ' Close the session
End If

GetFile function

Description:

Download a file from the FTP server.

Parameters:

  • Name of the file on the remote machine. This can be a fully qualified filename, or a plain filename. When using a plain filename, make sure you have changed the directory using ChangeDir.
  • Name of the file on the local machine. This can be a fully qualified filename, or a plain filename. When using a plain filename, the file will be stored in the current Windows directory.

Return value:

Always 0. Check LastError property to see if the function was completed successfully.

Example:

Set objFtpServer = CreateObject( "ActiveXperts.FtpServer" )     ' Create a new FtpServer 
                                                                ' instance
objFtpServer.Connect "ftpserver1", "account", "pwd"             ' Connect to host ftpserver1
If( objFtpServer.LastError = 0 ) Then
   ...
   objFtpServer.ChangeDir( "/pictures" )                        ' Change directory to: 
                                                                ' /pictures
   objFtpServer.GetFile( "picture1.jpg", _
     "c:\pictures\file1.jpg" )                                  ' Download 'picture1.jpg'
   ...
   objFtpServer.ChangeDir( "/" )                               ' Change directory to: /
   objFtpServer.GetFile( "/pictures/picture1.jpg", _
     "c:\pictures\file1.jpg" )                                 ' Download 'picture2.jpg'
   objFtpServer.Disconnect                                     ' Close the session
End If

PutFile function

Description:

Upload a file to the FTP server.

Parameters:

  • Name of the file on the local machine. This can be a fully qualified filename, or a plain filename. When using a plain filename, the file will be uploaded from the current Windows directory
  • Name of the file on the remote machine. This can be a fully qualified filename, or a plain filename. When using a plain filename, make sure you have changed the directory using ChangeDir.

Return value:

Always 0. Check LastError property to see if the function was completed successfully.

Example:

Set objFtpServer = CreateObject( "ActiveXperts.FtpServer" )     ' Create a new FtpServer 
                                                                ' instance
objFtpServer.Connect "ftpserver1", "account", "pwd"             ' Connect to host ftpserver1
If( objFtpServer.LastError = 0 ) Then
   ...
   objFtpServer.ChangeDir( "/pictures" )                        ' Change directory to: 
                                                                ' /pictures
   objFtpServer.PutFile( "c:\pictures\picture3.jpg", _
     "/pictures/picture3.jpg" )                                 ' Upload 'picture3.jpg'
   ...
   objFtpServer.PutFile( "c:\pictures\picture4.jpg", _
     "/pictures/picture4.jpg" )                                 ' Upload 'picture4.jpg'
End If

GetErrorDescription function

Description:

GetErrorDescription provides the error description of a given error code.

Parameters:

  • Error code.

Return value:

The error description that is associated with the given error code.

Example:

Set objFtpServer = CreateObject( "ActiveXperts.FtpServer" )     ' Create a new FtpServer 
                                                                ' instance
...
objFtpServer.Connect "ftpserver1", "account", "pwd"             ' Connect to host 
                                                                ' ftpserver1
WScript.Echo "LastError: " & objFtpServer.LastError
WScript.Echo "Error description: " & objFtpServer.GetErrorDescription( objFtpServer.LastError )
...

Sleep function

Description:

This function can be used in your script anywhere you want; Suspends the execution of the object for at least the specified interval.

Parameters:

  • The number of milliseconds to hold.

Return value:

Always 0. Check LastError property to see if the function was completed successfully.

Example:

Set objFtpServer   = CreateObject( "ActiveXperts.FtpServer" )   ' Create Ftperver object
Set objConstants   = CreateObject( "ActiveXperts.ASConstants" ) ' Create constants object
...
objFtpServer.Sleep 50

Activate function

Description:

This function activates the ActiveSocket product. A valid registration code is required.

Parameters:

  • The registration key
  • Persistent - this optional Boolean variable (default: True) specifies whether you want to add the registration key to the registry.
    If you pass 'True', you need to call the 'Activate' function only once for that computer.
    If you pass 'False', you need to call 'Activate' each time you create the object on that computer. This can be useful for customers who own a Distribution License of the product but do not want to show the registration key to their customers (see also here)

Return value:

Always 0. Check LastError property to see if the function was completed successfully.

Example:

Set objFtpServer = CreateObject( "ActiveXperts.FtpServer" )     ' Create FtpServer object
objFtpServer.Activate "xyz", True                               ' Substitute xyz by your 
                                                                ' own registrationkey
' Pass True to make the activation persistent, so you need to call
' Activate only once. If you pass False, you need to call Activate each time the product is 
' started.

8. FtpFile

8.1. Introduction

FTP stands for File Transfer Protocol: a communication standard which allows computers to transfer files back and forth in spite of differences in how different operating systems handle file names, directories and file formats.

The local (client) computer is the one you're directly connected to, and the remote (server) computer is the one that you want to get files from or put files to. You need to specify the Internet address of the remote computer, e.g. ftp.activexperts-labs.com.

Some sites maintain archives of files for public use, permitting access using the username anonymous. Usually you are asked to enter your real e-mail address as the password. If a site is not using anonymous FTP, you must provide the username and password which has been assigned to you for that computer.

FTP programmes have different methods of handling plain-text files and binary files. The plain-text mode attempts to correct for the different ways that different operating systems handle line breaks in text files, while the binary mode ensures that all of the special non-printing bytes are transferred without change. HTML files are plain-text files, while word-processing documents and images are binary files.

The following sample (VBScript) shows how the FtpServer and FtpFile objects can be used to list files in a specific directory on an FTP server:

Set objFtpServer = CreateObject ( "ActiveXperts.FtpServer" )

objFtpServer.Connect "ftp.activexperts-labs.com","anonymous","" ' Connect to the FTP server 
                                                                ' using the anonymous account 
Wscript.Echo "Connect, result: " & objFtpServer.LastError
If( objFtpServer.LastError <> 0 ) Then                          ' If connect failed then quit
   WScript.Quit
End If

objFtpServer.ChangeDir "samples/network-component/Visual Basic/Telnet"    ' Change directory
Wscript.Echo "ChangeDir, result: " & _
 objFtpServer.LastError
If( objFtpServer.LastError <> 0 ) Then                          ' If ChangeDir fails then 
                                                                ' disconnect and quit
   objFtpServer.Disconnect
   WScript.Quit
End If

Set objFtpFile = objFtpServer.FindFirstFile()                   ' Iterate over all files in dir 
                                                                ' Start with first file
While( objFtpServer.LastError = 0 )
   WScript.Echo "Name: " & objFtpFile.Name                      ' Display file name
   WScript.Echo "IsDirectory: " & objFtpFile.IsDirectory        ' Display directory or file
   WScript.Echo "Size: " & objFtpFile.Size                      ' Display file size
   WScript.Echo "Date: " & objFtpFile.Date                      ' Display file date
    
   ' To save the file, call the GetFile function. 
   ' strSaveAs = "C:\temp\" & objFtpFile.Name
   ' objFtpServer.GetFile objFtpFile.Name, strSaveAs
   ' Wscript.Echo "Save file, result: " & objFtpServer.LastError

   ' To delete a file, call the DeleteFile function. 
   ' objFtpServer.DeleteFile objFtpFile.Name
   ' Wscript.Echo "Delete, result: " & objFtpServer.LastError

   Set objFtpFile = objFtpServer.FindNextFile()                 ' Next file
Wend

objFtpServer.Disconnect                                         ' Disconnect

8.2. Properties

Properties

Property Type Read/Write Description
Name String Out Filename
IsDirectory Boolean Out Is the file a directory (True) or a file (False)
Size Number Out Size of file (in bytes)
DateSeconds Number Out Last modification date of the file (in seconds after 1/1/1970)
Date String Out Last modification date of the file (as a friendly string)

Name property

Type:

String

Description:

File name.

Example:

Set objFtpServer = CreateObject( "ActiveXperts.FtpServer" )     ' Create a new FtpServer 
                                                                ' instance
...
objFtpServer.Connect( "ftp01", "myaccount", "mypassword" )      ' Connect to the FTP server    
...
Set objFtpFile = objFtpServer.FindFirstFile()                   ' Get first file in the 
                                                                ' directory
If( objFtpServer.LastError = 0 ) Then                           
   WScript.Echo "Name   : " & objFtpFile.Name                   ' Display name of the file
   WScript.Echo "IsDirectory  : " & objFtpFile.IsDirectory      
   WScript.Echo "Size (in bytes) : " & objFtpFile.Size         
   WScript.Echo "DateSeconds : " & objFtpFile.DateSeconds      
   WScript.Echo "Date : " & objFtpFile.Date                     
End If
...
objFtpServer.Disconnect                                         ' Disconnect

IsDirectory property

Type:

Boolean

Description:

True indicates a directory, False indicates a file.

Example:

Set objFtpServer = CreateObject( "ActiveXperts.FtpServer" )     ' Create a new FtpServer 
                                                                ' instance
...
objFtpServer.Connect( "ftp01", "myaccount", "mypassword" )      ' Connect to the FTP server    
...
Set objFtpFile = objFtpServer.FindFirstFile()                   ' Get first file in the 
                                                                ' directory
If( objFtpServer.LastError = 0 ) Then                           
   WScript.Echo "Name   : " & objFtpFile.Name                   
   WScript.Echo "IsDirectory  : " & objFtpFile.IsDirectory      ' Display: Directory or File
   WScript.Echo "Size (in bytes) : " & objFtpFile.Size          
   WScript.Echo "DateSeconds : " & objFtpFile.DateSeconds       
   WScript.Echo "Date : " & objFtpFile.Date                     
End If
...
objFtpServer.Disconnect                                         ' Disconnect

Size property

Type:

Number

Description:

Size (in bytes) of the file.

Example:

Set objFtpServer = CreateObject( "ActiveXperts.FtpServer" )     ' Create a new FtpServer 
                                                                ' instance
...
objFtpServer.Connect( "ftp01", "myaccount", "mypassword" )      ' Connect to the FTP server    
...
Set objFtpFile = objFtpServer.FindFirstFile()                   ' Get first file in the 
                                                                ' directory
If( objFtpServer.LastError = 0 ) Then                           
   WScript.Echo "Name   : " & objFtpFile.Name                   
   WScript.Echo "IsDirectory  : " & objFtpFile.IsDirectory     
   WScript.Echo "Size (in bytes) : " & objFtpFile.Size          ' Display size in bytes
   WScript.Echo "DateSeconds : " & objFtpFile.DateSeconds       
   WScript.Echo "Date : " & objFtpFile.Date                    
End If
...
objFtpServer.Disconnect                                         ' Disconnect

DateSeconds property

Type:

Number

Description:

Last modification date and time of the file, in seconds after 1/1/1970.

Example:

Set objFtpServer = CreateObject( "ActiveXperts.FtpServer" )     ' Create a new FtpServer 
                                                                ' instance
...
objFtpServer.Connect( "ftp01", "myaccount", "mypassword" )      ' Connect to the FTP server    
...
Set objFtpFile = objFtpServer.FindFirstFile()                   ' Get first file in the 
                                                                ' directory
If( objFtpServer.LastError = 0 ) Then                           
   WScript.Echo "Name   : " & objFtpFile.Name                   
   WScript.Echo "IsDirectory  : " & objFtpFile.IsDirectory      
   WScript.Echo "Size (in bytes) : " & objFtpFile.Size         
   WScript.Echo "DateSeconds : " & objFtpFile.DateSeconds       ' Display last modification 
                                                                ' date/time in seconds after 
                                                                '1/1/1970
   WScript.Echo "Date : " & objFtpFile.Date                     
End If
...
objFtpServer.Disconnect                                         ' Disconnect

Date property

Type:

String

Description:

Last modification and time of the file, as a friendly string.

Example:

Set objFtpServer = CreateObject( "ActiveXperts.FtpServer" )     ' Create a new FtpServer 
                                                                ' instance
...
objFtpServer.Connect( "ftp01", "myaccount", "mypassword" )      ' Connect to the FTP server    
...
Set objFtpFile = objFtpServer.FindFirstFile()                   ' Get first file in the 
                                                                ' directory
If( objFtpServer.LastError = 0 ) Then                           
   WScript.Echo "Name   : " & objFtpFile.Name                  
   WScript.Echo "IsDirectory  : " & objFtpFile.IsDirectory      
   WScript.Echo "Size (in bytes) : " & objFtpFile.Size    
   WScript.Echo "DateSeconds : " & objFtpFile.DateSeconds     
   WScript.Echo "Date : " & objFtpFile.Date                     ' Display modification 
                                                                'date/time as a friendly string
End If
...
objFtpServer.Disconnect                                         ' Disconnect

9. Http

9.1. Introduction

Today, there are many software packages available to check web sites, like availability, contents, bandwidth, changes, etc..
However, most of these software tools are stand-alone packages, without scripting options. ActiveSocket is very well suited for scripting and embedding in applications.

The ActiveSocket Http object allows you to read web pages completely, so you can perform your own content checking. Use the ActiveSocket Http object to:

  • Check availability of web sites;
  • Make archives of web pages;
  • Compare web contents; for instance, read a web page every minute and notify when there's a certain change in the page;
  • Read output data of devices that provide a web interface; for instance, a Sensatronics IT Temperature device provides temperatures through a web interface (refreshed a couple of times per minute).
  • Any application that needs to read data from a web page;
  • Sending HTTP POST requests.

The ActiveSocket Http object doesn't require direct Internet access; it can operate through a proxy server (incl. support for proxy authentication). It also supports SSL secure web sites, including authentication.

Here is a small example (in VBScript) to show how to use the Http object:

Set objHttp = CreateObject("ActiveXperts.Http")                 ' Create HTTP object
objHttp.Connect( "www.activexperts.com/products" )              ' Connect to a remote server
WScript.Echo "Connect, result: " & objHttp.LastError
If( objHttp.LastError <> 0 ) Then
   WScript.Quit
End If

' Connection esablished; ready to read data
strData = objHttp.ReadData                                      ' Read data stream
If( objHttp.LastError <> 0 ) Then
   WScript.Echo "Error " & objHttp.LastError                    ' Failed to read data, print 
                                                                ' the error
Else
   WScript.Echo strData                                         ' Show data
End If

objHttp.Disconnect                                              ' Disconnect
WScript.Echo "Ready."

9.2. Properties

Properties

Property Type Read/Write Description
Version String Out Version number of ActiveSocket
Build String Out Display build information of ActiveSocket
ExpirationDate String Out Expiration date of ActiveSocket
LastError Number Out Result of the last called function
UseSSL Bool In/Out Access the page through SSL
UsePost Bool In/Out Specify to use HTTP-POST instead of HTTP-GET
PostData String In/Out Data to send with HTTP POST
RequestTimeout Number In/Out Timeout value for HTTP requests
KeepAlive Bool In/Out Specify to use the keepalive flag in the HTTP header
HttpLibrary String In/Out The preferred Http interface library
ProxyServer String In/Out Use a proxy server
ProxyAccount String In/Out Use this account for proxy authentication
ProxyPassword String In/Out Use this password for proxy authentication
WebAccount String In/Out Use this account to authenticate at the web site
WebPassword String In/Out Use this password to authenticate at the web site
LogFile String In/Out Log file; use it for troubleshooting purposes

Version property

Type:

String

Description:

Version information of ActiveSocket. This property is read-only; you cannot assign a value to it.

Example:

Set objHttp = CreateObject("ActiveXperts.Http")
WScript.Echo  "Version: " & objHttp.Version

Build property

Type:

String

Description:

Version information of ActiveSocket. This property is read-only; you cannot assign a value to it.

Example:

Set objHttp = CreateObject( "ActiveXperts.Http" )               ' Create Http object
WScript.Echo  "Build: " & objHttp.Build

ExpirationDate property

Type:

String

Description:

Expiration date of ActiveSocket. This property is read-only; you cannot assign a value to it. Once you have registered the product, the property holds the empty string ("") value.

Example:

Set objHttp    = CreateObject( "ActiveXperts.Http" )            ' Create Http object
Response.Write "ExpirationDate: " & objHttp.ExpirationDate

LastError property

Type:

Number

Description:

The result of a previous called function. Use it to check the result of your last function call. A zero indicates: success. Any non-zero value means an error.
The GetErrorDescription function provides the error description of an error code.
For a complete list of error codes, check out the following page: www.activexperts.com/support/errorcodes.

Example:

Set objHttp = CreateObject("ActiveXperts.Http")
...
objHttp.Connect "www.activexperts.com"
WScript.Echo "LastError: " & objHttp.LastError

UseSSL property

Type:

Boolean

Description:

Set this property to indicate that the Connect function must access the page through SSL. Connect discards the 'http://' and 'https://' prefixes, so settings the 'UseSSL' property is the only way to tell the Http object to use SSL.

Example:

Set objHttp = CreateObject("ActiveXperts.Http")
objHttp.UseSSL = True
...
objHttp.Connect "www.activexperts.com"                      
' To access http://www.activexperts.com

UsePost property

Type:

Boolean

Description:

Set this property to indicate that the Connect function must request the page using HTTP-POST. HTTP-POST is used to send a large number of bytes as parameters to a webserver.
The default value is disabled (use HTTP-GET).

Example:

Set objHttp = CreateObject("ActiveXperts.Http")
objHttp.UsePost = True
...
objHttp.Connect "www.activexperts.com/activsocket/postdemo/default.asp?parameter=200" 
                                                                ' HTTP/Post

PostData property

Type:

String

Description:

When the UsePost property is set, you can use this property to send additional data with the HTTP POST request.

Example:

Set objHttp = CreateObject("ActiveXperts.Http")
objHttp.UsePost  = True
objHttp.PostData = "a1=1;a2=2"
...
objHttp.Connect "www.activexperts.com/activsocket/postdemo/default.asp?parameter=200" 
                                                                ' HTTP/Post

RequestTimeout property

Type:

Number

Description:

By default the HTTP request timeout is set to 10 seconds. For large webpages, or pages that need to do some processing, you can use this property to increase the timeout. The value is specified in seconds.

Example:

Set objHttp = CreateObject("ActiveXperts.Http")
objHttp.RequestTimeout = 20
...
objHttp.Connect "www.activexperts.com/activsocket/postdemo/default.asp?parameter=200"

KeepAlive property

Type:

Boolean

Description:

Set this property to indicate that 'KeepAlive' value in the HTTP header is set to TRUE. This required for some rarely used authentication algorithms.

Example:

Set objHttp = CreateObject("ActiveXperts.Http")
objHttp.KeepAlive = True
...
objHttp.Connect "www.activexperts.com/activsocket/postdemo/default.asp?parameter=200"

HttpLibrary property

Type:

Number

Description:

ActiveSocket makes use of the WinHTTP library of the operating system. By default, the 'HttpLibrary' property is emtpy, and ActiveSocket will attempt to load WinHTTP5.dll. If WinHTTP5.dll fails to load, it will attempt to load WinHTTP.dll.
If you prefer another WinHTTP library, you can set the 'HttpLibrary' property. If set, ActiveSocket will ONLY attempt to load the specified library, it will not try other libraries after that. The 'HttpLibrary' property is used by the Connect function, so you must assign a value to it BEFORE calling the Connect function.

Example:

Set objHttp         = CreateObject("ActiveXperts.Http")
objHttp.HttpLibrary = "winhttp.dll"                             ' Load winhttp.dll
...
objHttp.Connect "www.activexperts.com"

ProxyServer property

Type:

String

Description:

If your Internet configuration requires access to a proxy server, you must assign the host name or IP address of the proxy server to the 'ProxyServer' property. Optionally, if proxy authentication is required, assign the proxy authentication values to the 'ProxyAccount' and 'ProxyPassword' properties. The proxy properties are used by the Connect function, so you must assign values to the proxy properties BEFORE calling the Connect function.

Example:

Set objHttp           = CreateObject("ActiveXperts.Http")
objHttp.ProxyServer   = "proxy01.intranet.dom"                  ' Access through a proxy
objHttp.ProxyAccount  = "mjackson"                              ' Proxy authentication required
objHttp.ProxyPassword = "mjackson1"                             ' Proxy authentication required
...
objHttp.Connect "www.activexperts.com"

ProxyAccount property

Type:

String

Description:

If your Internet configuration requires access to a proxy server, you must assign the host name or IP address of the proxy server to the 'ProxyServer' property. Optionally, if proxy authentication is required, assign the proxy authentication values to the 'ProxyAccount' and 'ProxyPassword' properties. The proxy properties are used by the Connect function, so you must assign values to the proxy properties BEFORE calling the Connect function.

Example:

Set objHttp           = CreateObject("ActiveXperts.Http")
objHttp.ProxyServer   = "proxy01.intranet.dom"                  ' Access through a proxy
objHttp.ProxyAccount  = "mjackson"                              ' Proxy authentication required
objHttp.ProxyPassword = "mjackson1"                             ' Proxy authentication required
...
objHttp.Connect "www.activexperts.com"

ProxyPassword property

Type:

String

Description:

If your Internet configuration requires access to a proxy server, you must assign the host name or IP address of the proxy server to the 'ProxyServer' property. Optionally, if proxy authentication is required, assign the proxy authentication values to the 'ProxyAccount' and 'ProxyPassword' properties. The proxy properties are used by the Connect function, so you must assign values to the proxy properties BEFORE calling the Connect function.

Example:

Set objHttp           = CreateObject("ActiveXperts.Http")
objHttp.ProxyServer   = "proxy01.intranet.dom"                  ' Access through a proxy
objHttp.ProxyAccount  = "mjackson"                              ' Proxy authentication required
objHttp.ProxyPassword = "mjackson1"                             ' Proxy authentication required
...
objHttp.Connect "www.activexperts.com"

WebAccount property

Type:

String

Description:

If access to the web page requires authentication, you must assign the 'WebAccount' and 'WebPassword' properties. The 'WebAccount' and 'WebPassword' properties are used by the Connect function, so you must assign values to these properties BEFORE calling the Connect function.

Example:

Set objHttp = CreateObject("ActiveXperts.Http")
...
objHttp.WebAccount = "user_a" ' Website requires authentication
objHttp.WebPassword = "password_a" ' Website requires authentication
objHttp.Connect "www.activexperts.com:80/about"

WebPassword property

Todo

LogFile property

Type:

String

Description:

For troubleshooting purposes, you can specify a log file to trace all operations. By default, the 'LogFile' property holds the empty string. By assigning a valid filename to it, all operations will be written to this log file.

Example:

Set objHttp = CreateObject("ActiveXperts.Http")
...
objHttp.LogFile = "c:\file.log"
objHttp.Connect "www.activexperts.com:80/about"

9.3. Functions

Functions

Function Description
Clear Reset all properties to default
Connect Connect to a web site
Disconnect Disconnect from a web site
ReadHeader Read HTTP header
ReadData Read data from the web page
GetErrorDescription Get the error description
Sleep Suspends the execution of the object for at least the specified interval
Activate Activate the product

Clear function

Description:

Resets all properties to the initial value.

Parameters:

Return value:

Always 0.

Example:

Set objHttp = CreateObject("ActiveXperts.Http")
...
objHttp.Connect "www.activexperts.com:8080/products/"
If( objHttp.LastError = 0 ) Then
  ...
End If

Connect function

Description:

Connect to a web page. You must connect to a web page before you can use the ReadData to actually read the data from the page. The 'Connect' function requires one parameter: the URL. The 'http://' and 'https://' prefixes are ignored by the 'Connect' function. You can include a port number and a relative path in the URL.

Parameters:

  • URL - The URL consists of a host name (or IP address), optionally a port number, and a relative path

Return value:

Always 0. Check LastError property to see if the function was completed successfully.

Example:

Set objHttp = CreateObject("ActiveXperts.Http")
...
objHttp.Connect "www.activexperts.com:8080/products/"
If( objHttp.LastError = 0 ) Then
  ...
End If

Disconnect function

Description:

Disconnect from a web site. You must disconnect from a web page when you don't want to read data from the page anymore. The 'Disconnect' function only disconnects a session if you already made a connection to the page though the Connect function. If there is no connection, 'Disconnect' returns immediately with no error.

Parameters:

  • None

Return value:

Always 0. Check LastError property to see if the function was completed successfully.

Example:

Set objHttp = CreateObject("ActiveXperts.Http")
...
objHttp.Connect "www.activexperts.com/products"
If( objHttp.LastError = 0 ) Then
  ...
  objHttp.Disconnect
End If

ReadHeader function

Description:

Read the HTTP header of the site you are connecting to. You must connect to a web page before you can read the HTTP header from the remote site.

Parameters:

Return value:

The header that was read from the site. If the function fails, an empty string is retunred and LastError property is set.

Example:

Set objHttp = CreateObject("ActiveXperts.Http")
...
objHttp.Connect "www.activexperts.com"
If( objHttp.LastError = 0 )
  strData = objHttp.ReadHeader( 1 )                             '  1 means: Content-type
  WScript.Echo strData
  strData = objHttp.ReadHeader( 3 )                             '  3 means: Content-ID
  WScript.Echo strData
  strData = objHttp.ReadHeader( 35 )                            ' 35 means: Referer
  WScript.Echo strData
End If

ReadData function

Http.ReadData function

Description:

Read all data from the web page. You must connect to a web page before you can read the data from the page.

Parameters:

  • None

Return value:

The data that was read from the web page. If the function fails, an empty string is returned and LastError property is set.

Example:

Set objHttp = CreateObject("ActiveXperts.Http")
...
objHttp.Connect "www.activexperts.com"
If( objHttp.LastError = 0 )
  strData = objHttp.ReadData
  If( objHttp.LastError = 0 )
    WScript.Echo strData
  End If
End If

GetErrorDescription function

Description:

GetErrorDescription provides the error description of a given error code.

Parameters:

  • Error code

Return value:

The error description that is associated with the given error code.

Example:

Set objHttp = CreateObject("ActiveXperts.Http")
...
objHttp.Connect "www.thispagedoesnotexist.dom/about"
WScript.Echo "LastError: "         & objHttp.LastError
WScript.Echo "Error description: " & objHttp.GetErrorDescription( objHttp.LastError )

Sleep function

Description:

This function can be used in your script anywhere you want; Suspends the execution of the object for at least the specified interval.

Parameters:

  • The number of milliseconds to hold

Return value:

Always 0.

Example:

Set objHttp        = CreateObject( "ActiveXperts.Http" )         ' Create Http object
...
objHttp.Sleep 500

Activate function

Description:

This function activates the ActiveSocket product. A valid registration code is required.

Parameters:

  • The registration key
  • Persistent - this optional Boolean variable (default: True) specifies whether you want to add the registration key to the registry.
    If you pass 'True', you need to call the 'Activate' function only once for that computer.
    If you pass 'False', you need to call 'Activate' each time you create the object on that computer. This can be useful for customers who own a Distribution License of the product but do not want to show the registration key to their customers (see also here)

Return value:

Always 0. Check LastError property to see if the function was completed successfully.

Example:

  Set objHttp         = CreateObject( "ActiveXperts.Http" )     ' Create Http object
  objHttp.Activate "xyz", True                                  ' Substitute xyz by your 
                                                                own registrationkey
' Pass True to make the activation persistent, so you need to call
' Activate only once. If you pass False, you need to call
' Activate each time the product is started.

10. HttpEx

10.1. Introduction

The HttpEx object provides a very simple interface to commonly used HTTP functions. This object uses connection pooling to speed up multiple calls to the same webserver. This will enhance performance for applications which need to get an entire web page including images, stylesheets, scriptfiles etc..

The function calls used in this object are analogous to the verbs that are used in the HTTP protocol. For instance, the http GET verb, which is the default way for a browser to query a web page, is translated to the 'Get' function.

In addition this object supports the use of proxy servers and webauthentication. If also supports SSL and TLS encryption methods.

Here is a small example (in VBScript) to show how to use the HttpEx object:

Set objHttpEx = CreateObject("ActiveXperts.HttpEx")             ' Create HttpEx object
WScript.Echo objHttpEx.Get( "www.activexperts.com/products" )   ' Echo the contents of 
                                                                ' the products page  
If( objHttpEx.LastError <> 0 ) Then
   WScript.Echo "Error " & objHttpEx.LastError              ' Failed to get the web page, 
                                                                ' print the error
End If
WScript.Echo "Ready."

10.2. Properties

Properties

Property Type Read/Write Description
Version String Out Version number of ActiveSocket
Build String Out Display build information of ActiveSocket
ExpirationDate String Out Expiration date of ActiveSocket
LastError Number Out Result of the last called function
LastResponseCode Number Out Last HTTP response code
RequestTimeout Number In/Out Timeout value for HttpEx requests
ConnectionExpireTimeout Number In/Out Timeout value for connections to expire and be elegible for removal from the connection pool
ConnectionPoolSize Number In/Out The number of active connection that can be kept in the connection pool at one time
UserAgent String In/Out The user agent string that will be provided when making requests or posts
FollowRedirect Boolean In/Out Whether or not redirect a HTTP redirect will be automatically followed
MaxRedirectionDepth Number In/Out The maximum number of redirections to follow on a single request
ProxyServer String In/Out Use a proxy server
ProxyAccount String In/Out Use this account for proxy authentication
ProxyPassword String In/Out Use this password for proxy authentication
WebAccount String In/Out Use this account to authenticate at the web site
WebPassword String In/Out Use this password to authenticate at the web site
LogFile String In/Out Log file; use it for troubleshooting purposes

Version property

Type:

String

Description:

Version information of ActiveSocket. This property is read-only; you cannot assign a value to it.

Example:

Set objHttpEx = CreateObject("ActiveXperts.HttpEx")
WScript.Echo  "Version: " & objHttpEx.Version

Build property

Type:

String

Description:

Version information of ActiveSocket. This property is read-only; you cannot assign a value to it.

Example:

Set objHttpEx = CreateObject( "ActiveXperts.HttpEx" )           ' Create HttpEx object
WScript.Echo  "Build: " & objHttpEx.Build

ExpirationDate property

Type:

String

Description:

Expiration date of ActiveSocket. This property is read-only; you cannot assign a value to it. Once you have registered the product, the property holds the empty string ("") value.

Example:

Set objHttpEx    = CreateObject( "ActiveXperts.HttpEx" )        ' Create HttpEx object
Response.Write "ExpirationDate: " & objHttpEx.ExpirationDate

LastError property

Type:

Number

Description:

The result of a previous called function. Use it to check the result of your last function call. A zero indicates: success. Any non-zero value means an error.
The GetErrorDescription function provides the error description of an error code.
For a complete list of error codes, check out the following page: www.activexperts.com/support/errorcodes.

Example:

Set objHttpEx = CreateObject("ActiveXperts.HttpEx")
...
objHttpEx.Get "www.activexperts.com"
WScript.Echo "LastError: " & objHttpEx.LastError

LastResponseCode property

Type:

Number

Description:

The last received HTTP response code. Use this to check the HTTP response after a Get, Post or Head function call. When a HTTP call succeeded the response code should be 200 (Ok). More information about HTTP response codes can be found here.

Example:

Set objHttpEx = CreateObject("ActiveXperts.HttpEx")
...
objHttpEx.Get "www.activexperts.com"
WScript.Echo "LastError: " & objHttpEx.LastError
Wscript.Echo "HTTP Response: " & objHttpEx.LastResponseCode

RequestTimeout property

Type:

Number

Description:

For large webpages, or pages that need to do some processing, you can use this property to increase the timeout. By default the HttpEx request timeout is set to 10 seconds. The value is specified in milliseconds.

Example:

Set objHttpEx = CreateObject("ActiveXperts.HttpEx")
objHttpEx.RequestTimeout = 20000
...
objHttpEx.Get "www.activexperts.com/activsocket/postdemo/default.asp?parameter=200"

ConnectionExpireTimeout property

Type:

Number

Description:

Timeout value for connections to expire and be elegible for removal from the connection pool. By default the ConnectionExireTimeout is set to 30 seconds. The value is specified in milliseconds.

Example:

Set objHttpEx = CreateObject("ActiveXperts.HttpEx")
objHttpEx.ConnectionExpireTimeout = 300000
...
objHttpEx.Get "www.activexperts.com/activsocket/postdemo/default.asp?parameter=200"

ConnectionPoolSize property

Type:

Number

Description:

The number of active connection that can be kept in the connection pool at one time. If the connection pool is full expired connections will be removed. If no connections have expired the oldest connection will be removed in favor of the new connection. By default this value is set to 32.

Example:

Set objHttpEx = CreateObject("ActiveXperts.HttpEx")
objHttpEx.ConnectionPoolSize = 5
...
objHttpEx.Get "www.activexperts.com/activsocket/postdemo/default.asp?parameter=200"

UserAgent property

Type:

String

Description:

Set this property to indicate which user agent is used to connect to a website. Some webservers will host different pages according to browser vendor or version.

Example:

Set objHttpEx = CreateObject("ActiveXperts.HttpEx")
objHttpEx.UserAgent = "Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.3)"
...
objHttpEx.Get "www.activexperts.com"

FollowRedirect property

Type:

Boolean

Description:

Whether or not a HTTP redirect (HTTP code 301 or 302) will be automatically followed. This property is set to True by default.

Example:

Set objHttpEx = CreateObject("ActiveXperts.HttpEx")
objHttpEx.FollowRedirect = False
...
objHttpEx.Get "http://google.com"

MaxRedirectionDepth property

Type:

Number

Description:

When the FollowRedirect properties is set to true, this is the maximum number of redirections that will be followed before cancelling the request.

Example:

Set objHttpEx = CreateObject("ActiveXperts.HttpEx")
objHttpEx.MaxRedirectionDepth = 10
...
objHttpEx.Get "http://google.com"

ProxyServer property

Type:

String

Description:

If your Internet configuration requires access to a proxy server, you must assign the host name or IP address of the proxy server to the 'ProxyServer' property. Optionally, if proxy authentication is required, assign the proxy authentication values to the 'ProxyAccount' and 'ProxyPassword' properties. The proxy properties are used by the Connect function, so you must assign values to the proxy properties BEFORE calling the Connect function.

Example:

Set objHttp           = CreateObject("ActiveXperts.Http")
objHttp.ProxyServer   = "proxy01.intranet.dom"  ' Access through a proxy
objHttp.ProxyAccount  = "mjackson"              ' Proxy authentication required
objHttp.ProxyPassword = "mjackson1"             ' Proxy authentication required
...
objHttp.Connect "www.activexperts.com"

ProxyAccount property

Type:

String

Description:

If your Internet configuration requires access to a proxy server, you must assign the host name or IP address of the proxy server to the 'ProxyServer' property. Optionally, if proxy authentication is required, assign the proxy authentication values to the 'ProxyAccount' and 'ProxyPassword' properties. The proxy properties are used by the Connect function, so you must assign values to the proxy properties BEFORE calling the Connect function.

Example:

Set objHttp           = CreateObject("ActiveXperts.Http")
objHttp.ProxyServer   = "proxy01.intranet.dom"  ' Access through a proxy
objHttp.ProxyAccount  = "mjackson"              ' Proxy authentication required
objHttp.ProxyPassword = "mjackson1"             ' Proxy authentication required
...
objHttp.Connect "www.activexperts.com"

ProxyPassword property

Type:

String

Description:

If your Internet configuration requires access to a proxy server, you must assign the host name or IP address of the proxy server to the 'ProxyServer' property. Optionally, if proxy authentication is required, assign the proxy authentication values to the 'ProxyAccount' and 'ProxyPassword' properties. The proxy properties are used by the Connect function, so you must assign values to the proxy properties BEFORE calling the Connect function.

Example:

Set objHttp           = CreateObject("ActiveXperts.Http")
objHttp.ProxyServer   = "proxy01.intranet.dom"  ' Access through a proxy
objHttp.ProxyAccount  = "mjackson"              ' Proxy authentication required
objHttp.ProxyPassword = "mjackson1"             ' Proxy authentication required
...
objHttp.Connect "www.activexperts.com"

WebAccount property

Type:

String

Description:

If your Internet configuration requires access to a proxy server, you must assign the host name or IP address of the proxy server to the 'ProxyServer' property. Optionally, if proxy authentication is required, assign the proxy authentication values to the 'ProxyAccount' and 'ProxyPassword' properties. The proxy properties are used by the Connect function, so you must assign values to the proxy properties BEFORE calling the Connect function.

Example:

Set objHttp           = CreateObject("ActiveXperts.Http")
objHttp.ProxyServer   = "proxy01.intranet.dom"  ' Access through a proxy
objHttp.ProxyAccount  = "mjackson"              ' Proxy authentication required
objHttp.ProxyPassword = "mjackson1"             ' Proxy authentication required
...
objHttp.Connect "www.activexperts.com"

WebPassword property

Type:

String

Description:

If your Internet configuration requires access to a proxy server, you must assign the host name or IP address of the proxy server to the 'ProxyServer' property. Optionally, if proxy authentication is required, assign the proxy authentication values to the 'ProxyAccount' and 'ProxyPassword' properties. The proxy properties are used by the Connect function, so you must assign values to the proxy properties BEFORE calling the Connect function.

Example:

Set objHttp           = CreateObject("ActiveXperts.Http")
objHttp.ProxyServer   = "proxy01.intranet.dom"  ' Access through a proxy
objHttp.ProxyAccount  = "mjackson"              ' Proxy authentication required
objHttp.ProxyPassword = "mjackson1"             ' Proxy authentication required
...
objHttp.Connect "www.activexperts.com"

LogFile property

Type:

String

Description:

For troubleshooting purposes, you can specify a log file to trace all operations. By default, the 'LogFile' property holds the empty string. By assigning a valid filename to it, all operations will be written to this log file.

Example:

Set objHttpEx = CreateObject("ActiveXperts.HttpEx")
...
objHttpEx.LogFile = "c:\file.log"
objHttpEx.Get "www.activexperts.com:80/about"

10.3. Functions

Functions

Function Description
Clear Reset all properties to default
Get Gets the contents of a website as a string using an HTTP GET request
GetFile Downloads the contents of a website to a file using an HTTP GET request
Head Gets the headers for a website using the HTTP HEAD command
Post Post string data to a webpage and returns the response as a string using the HTTP POST command
SetHeader Set a custom header value for future GET or POST requests
UrlEncode Url Encode a given string
GetErrorDescription Get the error description
Sleep Suspends the execution of the object for at least the specified interval
Activate Activate the product

Clear function

Description:

Resets all properties to the initial value.

Parameters:

Return value:

Always 0.

Example:

Set objHttpEx = CreateObject("ActiveXperts.HttpEx")
...
objHttpEx.SetHeader "Connection", "Keep-Alive"
objHttpEx.Clear
objHttpEx.Get "www.activexperts.com:8080/products/"
If( objHttpEx.LastError = 0 ) Then
  ...
End If

Get function

Description:

Get the contents of a webpage from a webserver and return it as a string value. This function defaults to non secure connections using the default HTTP port 80. The use of SSL or a diffent port can be specified as usual, e.g. https://cruisecontrol.intra:8080/dashboard connects securely on port 8080.

Parameters:

  • URL - The URL consists of a host name (or IP address), optionally a port number, and a relative path

Return value:

Always 0. Check LastError property to see if the function was completed successfully.

Example:

Set objHttpEx = CreateObject("ActiveXperts.HttpEx")
...
WScript.Echo objHttpEx.Get("www.activexperts.com:8080/products/")
If( objHttpEx.LastError = 0 ) Then
  ...
End If

GetFile function

Description:

Get the contents of a webpage from a webserver and save it to a file. This function defaults to non secure connections using the default HTTP port 80. The use of SSL or a diffent port can be specified as usual, e.g. https://cruisecontrol.intra:8080/dashboard connects securely on port 8080.

Parameters:

  • URL - The URL consists of a host name (or IP address), optionally a port number, and a relative path

Return value:

Always 0. Check LastError property to see if the function was completed successfully.

Example:

Set objHttpEx = CreateObject("ActiveXperts.HttpEx")
...
objHttpEx.GetFile "www.activexperts.com:8080/products/", "C:\products.txt"
If( objHttpEx.LastError = 0 ) Then
  ...
End If

Head function

Description:

Get the headers of a webpage from a webserver and return it as a string value. This function defaults to non secure connections using the default HTTP port 80. The use of SSL or a diffent port can be specified as usual, e.g. https://cruisecontrol.intra:8080/dashboard connects securely on port 8080.

Parameters:

  • URL - The URL consists of a host name (or IP address), optionally a port number, and a relative path

Return value:

Always 0. Check LastError property to see if the function was completed successfully.

Example:

Set objHttpEx = CreateObject("ActiveXperts.HttpEx")
...
WScript.Echo objHttpEx.Head("www.slashdot.org")
If( objHttpEx.LastError = 0 ) Then
  ...
End If

Post function

Description:

Post a string to a website and returns the result as a string value. This function defaults to non secure connections using the default HTTP port 80. The use of SSL or a diffent port can be specified as usual, e.g. https://cruisecontrol.intra:8080/dashboard connects securely on port 8080.

Parameters:

  • URL - The URL consists of a host name (or IP address), optionally a port number, and a relative path

Return value:

Always 0. Check LastError property to see if the function was completed successfully.

Example:

Set objHttpEx = CreateObject("ActiveXperts.HttpEx")
...
WScript.Echo objHttpEx.Post("www.activexperts.com:8080/products/", 
"COMPANY_NAME=test&COMPANY_URL=http://example.com")
If( objHttpEx.LastError = 0 ) Then
  ...
End If

SetHeader function

Description:

Set a custom HTTP header which will be include in future requests or posts made to a webserver. The header value will clear any header value of the same name that was previously set. To clear all header values call the Clear function.

Parameters:

  • Header - The name of the header
  • Value - The value

Return value:

Always 0. Check LastError property to see if the function was completed successfully.

Example:

Set objHttpEx = CreateObject("ActiveXperts.HttpEx")
...
objHttpEx.SetHeader("Connection", "Keep-Alive")
WScript.Echo objHttpEx.Get("http://www.activexperts.com")
If( objHttpEx.LastError = 0 ) Then
  ...
End If

UrlEncode function

Description:

UrlEncode function encodes the given string. Use this function to encode parameters when using HttpEx to 'POST' or 'GET' specific parameters to a website.

Parameters:

  • Input string

Return value:

An encoded copy of the input string

Example:

Set objHttpEx = CreateObject("ActiveXperts.HttpEx")
...
Url = "http://www.google.com/search?hl=en&q=" & objHttpEx.UrlEncode("Hello, World !")
Wscript.Echo objHttpEx.Get(Url)
WScript.Echo "LastError: "         & objHttpEx.LastError
WScript.Echo "Error description: " & objHttpEx.GetErrorDescription( objHttpEx.LastError )

GetErrorDescription function

Description:

GetErrorDescription provides the error description of a given error code.

Parameters:

  • Error code

Return value:

The error description that is associated with the given error code.

Example:

Set objHttpEx = CreateObject("ActiveXperts.HttpEx")
...
objHttpEx.Get "www.thispagedoesnotexist.dom/about"
WScript.Echo "LastError: "         & objHttpEx.LastError
WScript.Echo "Error description: " & objHttpEx.GetErrorDescription( objHttpEx.LastError )

Sleep function

Description:

This function can be used in your script anywhere you want; Suspends the execution of the object for at least the specified interval.

Parameters:

  • The number of milliseconds to hold

Return value:

Always 0.

Example:

Set objHttpEx        = CreateObject( "ActiveXperts.HttpEx" )         ' Create HttpEx object
...
objHttpEx.Sleep 500

Activate function

Description:

This function activates the ActiveSocket product. A valid registration code is required.

Parameters:

  • The registration key
  • Persistent - this optional Boolean variable (default: True) specifies whether you want to add the registration key to the registry.
    If you pass 'True', you need to call the 'Activate' function only once for that computer.
    If you pass 'False', you need to call 'Activate' each time you create the object on that computer. This can be useful for customers who own a Distribution License of the product but do not want to show the registration key to their customers (see also here)

Return value:

Always 0. Check LastError property to see if the function was completed successfully.

Example:

Set objHttpEx         = CreateObject( "ActiveXperts.HttpEx" ) ' Create HttpEx object
objHttpEx.Activate "xyz", True                ' Substitute xyz by your own registrationkey
' Pass True to make the activation persistent, so you need to call
' Activate only once. If you pass False, you need to call
' Activate each time the product is started.

11. Icmp

11.1. Introduction

ICMP/Ping is one of the most commonly used utilities on the Internet by people and programs, with untold millions of pings flashing every second back and forth between computers. The original PING utility stood for "Packet Internet Groper", and was a package of diagnostic utilities used by DARPA personnel to test the performance of the ARPANET. Almost every operating system includes a Ping program. It has become one of the most versatile and widely used diagnostic tools on the Internet.

ICMP/Ping sends a small packet of information containing an ICMP ECHO_REQUEST to a specified computer, which then sends an ECHO_REPLY packet in return.

You can use Ping to perform several useful network diagnostics, such as the following:

  • Access - You can use Ping to see if you can reach another computer. If you can't ping a site at all, but you can ping other sites, then it's a pretty good sign that your network is fine and that site is down. On the other hand, if you can't ping any site, then likely your entire network connection is down - try rebooting;
  • Time & distance. You can use Ping to determine how long it takes to bounce a packet off of another site, which tells you its distance in network terms. For example, a site hosted on your neighbor's computer next door with a different Internet service provider might go through more routers and be farther away in network distance than a site on the other side of the ocean with a direct connection to the Internet backbone. If a site seems slow, you can compare ping distances to other sites to determine whether it is the site, the network, or your system that is slow. You can also compare ping times to get an idea of which sites have the fastest network access and would be most efficient for downloading, chat, and other applications;
  • Domain IP address. You can ping either a domain name or an IP address. If you ping a domain name, it will helpfully display the corresponding IP address in the response.

The ActiveSocket Icmp object enables you to add Icmp/Ping functionality to your program.
Here is a small example (in VBScript) to show how to use the Icmp object:

Set objIcmp        = CreateObject("ActiveXperts.Icmp")          ' Create Icmp object
objIcmp.Ping "www.activexperts.com", 2000                       ' Ping host; timeout 2000 ms
If( objIcmp.LastError = 0 ) Then
 WScript.Echo "Success, duration: " & objIcmp.LastDuration & "ms"
Else
 WScript.Echo "Error " & objIcmp.LastError & ": " &_
  objIcmp.GetErrorDescription( objIcmp.LastError )
End If
WScript.Echo "Ready."

11.2. Properties

Properties

Property Type Read/Write Description
Version String Out Version number of ActiveSocket
Build String Out Display build information of ActiveSocket
ExpirationDate String Out Expiration date of ActiveSocket
LogFile String In/Out Log file; use it for troubleshooting purposes
Ttl Number In/Out Maximum Time To Live in next Ping call
BufferSize Number In/Out Send buffer size
LastError Number Out Result of the last called function
LastDuration Number Out Reply time of the last Ping call
LastTtl Number Out TTL of last Ping call

Version property

Type:

String

Description:

Version information of ActiveSocket. This property is read-only; you cannot assign a value to it.

Example:

Set objIcmp = CreateObject( "ActiveXperts.Icmp" )          ' Create Icmp object
WScript.Echo  "Version: " & objIcmp.Version

Build property

Type:

String

Description:

Build information of ActiveSocket. This property is read-only; you cannot assign a value to it.

Example:

Set objIcmp = CreateObject( "ActiveXperts.Icmp" )          ' Create Icmp object
WScript.Echo  "Build: " & objIcmp.Build

ExpirationDate property

Type:

String

Description:

Expiration date of ActiveSocket. This property is read-only; you cannot assign a value to it.
Once you have registered the product, the property holds the empty string ("") value.

Example:

Set objIcmp = CreateObject( "ActiveXperts.Icmp" )          ' Create Icmp object
WScript.Echo "ExpirationDate: " & objIcmp.ExpirationDate

LogFile property

Type:

String

Description:

For troubleshooting purposes, you can specify a log file to trace all operations. By default, the 'LogFile' property holds the empty string. By assigning a valid filename to it, all operations will be written to this log file.

Example:

Set objIcmp = CreateObject( "ActiveXperts.Icmp" )          ' Create Icmp object
objIcmp.LogFile = "c:\file.log

Ttl property

Type:

Number

Description:

Time To Live to be used in the next Ping call. Value must be between 1 and 255. Default value is 255.

Example:

Set objIcmp  = CreateObject( "ActiveXperts.Icmp" )
objIcmp.Ttl  = 100                                              ' Use a different Time To Live 
                                                                ' than the default 255 value
objIcmp.Ping "www.monitortools.com", 2000                       ' Ping monitortools.com,timeout
                                                                ' after 2000 msec
If( objIcmp.LastError = 0 ) Then
  WScript.Echo "TTL: " & objIcmp.LastTtl
End If

BufferSize property

Type:

Number

Description:

Buffer size (in bytes) to be used in the next Ping call. Value must be between 0 and 8192. Default value is 32 (bytes).

Example:

Set objIcmp         = CreateObject( "ActiveXperts.Icmp" )       ' Create Icmp object
objIcmp.BufferSize  = 64                                        ' Use a different buffer size
                                                                ' than the default (32 bytes)
objIcmp.Ping "www.monitortools.com", 2000                       ' Ping monitortools.com,timeout 
                                                                ' after 2000 msec

LastError property

Type:

Number

Description:

The result of a previous called function. Use it to check the result of your last function call. A zero indicates: success. Any non-zero value means an error.
The GetErrorDescription function provides the error description of an error code.
For a complete list of error codes, check out the following page: www.activexperts.com/support/errorcodes.

Example:

Set objIcmp = CreateObject( "ActiveXperts.Icmp" )               ' Create Icmp object
objIcmp.Ping "server.mydomain.com", 2000
WScript.Echo "LastError: " & objIcmp.LastError

LastDuration property

Type:

Number

Description:

The duration of the last Ping call. The property is read-only; you cannot assign a value to it.

Example:

Set objIcmp = CreateObject( "ActiveXperts.Icmp" )               ' Create Icmp object
objIcmp.Ping "www.activexperts.com", 2000
WScript.Echo "Duration of ICMP/Ping operation: " & objIcmp.LastDuration

LastTtl property

Type:

Number

Description:

The Time To Live value of the last Ping call. The property is read-only; you cannot assign a value to it.
The maximum Time To Live value is indicated by the Ttl property. The default maximum Time To Live value is 255, but you can assign any value between 1 and 255 to it.

Example:

Set objIcmp = CreateObject( "ActiveXperts.Icmp" )               ' Create Icmp object
objIcmp.Ping "www.monitortools.com", 2000
If( objIcmp.LastError = 0 ) Then
  WScript.Echo "TTL: " & objIcmp.LastTtl
End If

11.3. Functions

Functions

Function Description
Clear Clear all properties
Ping Ping the specified host
GetErrorDescription Get the description of the given error
Sleep Suspends the execution of the object for at least the specified interval

Clear function

Description:

Reset all properties to their initial values. Use this function when you make consecutive calls to the Ping function.

Parameters:

  • None

Return value:

Always 0.

Example:

Set objIcmp  = CreateObject( "ActiveXperts.Icmp" )              ' Create Icmp object
objIcmp.Ping "192.168.1.1", 2000
objIcmp.Clear
objIcmp.Ping "192.168.1.2", 2000

Ping function

Description:

Ping the specified host. The function requires one parameter: the host that you want to check.

Parameters:

  • Host - Can be a host name, a NetBios name or an IP address
  • Timeout - Timeout in milliseconds to wait for a reply

Return value:

Always 0. Check LastError property to see if the function was completed successfully.

Example:

Set objIcmp  = CreateObject( "ActiveXperts.Icmp" )              ' Create Icmp object
objIcmp.Ping "192.168.1.1", 2000
objIcmp.Clear
objIcmp.Ping "192.168.1.2", 2000

GetErrorDescription function

Description:

GetErrorDescription provides the error description of a given error code.

Parameters:

  • Error code

Return value:

The error description that is associated with the given error code.

Example:

Set objIcmp  = CreateObject( "ActiveXperts.Icmp" )              ' Create Icmp object
objIcmp.Ping "www.thisdoesnotexist.com", 2000
WScript.Echo "LastError: " & objIcmp.LastError
WScript.Echo "Error description: " & objIcmp.GetErrorDescription( objIcmp.LastError )

Sleep function

Description:

This function can be used in your script anywhere you want. Suspends the execution of the object for at least the specified interval.

Parameters:

  • The number of milliseconds to suspend

Return value:

Always 0.

Example:

Set objIcmp        = CreateObject( "ActiveXperts.Icmp" )        ' Create Icmp object
...
objIcmp.Sleep 500

12. IPtoCountry

12.1. Introduction

Today there are millions of internet users around the world. There are also numerous products and services available on the internet.

There are some key benefits of determines the country by IP address:

  • Marketing - adapt your business, web content or language according to the geographic location of the visitor;
  • Restrict access - restrict software or sites for users, based on the geographic location of the visitor;
  • Web server log analysis - restrict software or sites for users, based on the geographic location of the visitor;
  • Reduce credit card fraud.

The IPtoCountry object translates IP address to countries. It makes use of an internal IP-to-Coiuntry database, which resides as a data segment in the ActiveSocket core component: ASocket.dll. The accuracy is over 95%. The inaccuracy is due to dynamic IP address allocation by large ISPs such as AOL and MSN TV. It is also due to the use of proxy servers.

Here is a small example (in VBScript) to show how to use the IPtoCountry object and translate an IP address to a country:

Set objSnmpMib = CreateObject( "ActiveXperts.SnmpMibBrowser" )     ' Create instance of snmp mib
                                                                   ' browser

objSnmpMib.LoadMibFile( "c:\windows\system32\hostmib.mib" )     ' Load MIB file
WScript.Echo "LoadMibFile, result: " & objSnmpMib.LastError
If( objSnmpMib.LastError <> 0 ) Then
  WScript.Quit 
End If

Set objSnmp = objSnmpMIB.Get("iso")                             ' Get first OID
While(objSnmpMIB.LastError = 0 )
  WScript.Echo "OID Name: " & objSnmp.Name & "; Full-path: " & objSnmp.Path
  WScript.Echo "  Description: " & objSnmp.Description
  WScript.Echo "  Access: " & objSnmp.Access
  WScript.Echo "  Status: " & objSnmp.Status                   
  Set objSnmp = objSnmpMIB.GetNext()                            ' Get next OID
WEnd

12.2. Properties

Properties

Property Type Read/Write Description
Version String Out Version number of ActiveSocket
Build String Out Display build information of ActiveSocket
ExpirationDate String Out Expiration date of ActiveSocket
Host String In/Out Host or IP address to be translated to a country
CountryCode String Out Two-character country code (ISO 3166) associated with the given host or IP address
CountryCodeEx String Out Three-character country code (ISO 3166) associated with the given host or IP address
CountryName String Out Country name associated with the given host or IP address
LastError Number Out Result of the Query function
LogFile String In/Out Log file; use it for troubleshooting purposes

Version property

Type:

String

Description:

Version information of ActiveSocket. This property is read-only; you cannot assign a value to it.

Example:

Set objIPC = CreateObject( "ActiveXperts.IPtoCountry" )         ' Create IPtoCountry object
WScript.Echo  "Version: " & objIPC.Version

Build property

Type:

String

Description:

Build information of ActiveSocket. This property is read-only; you cannot assign a value to it.

Example:

Set objIPC = CreateObject( "ActiveXperts.IPtoCountry" )         ' Create IPtoCountry object
WScript.Echo  "Build: " & objIPC.Build

ExpirationDate property

Type:

String

Description:

Expiration date of ActiveSocket. This property is read-only; you cannot assign a value to it.
Once you have registered the product, the property holds the empty string ("") value.

Example:

Set objIPC = CreateObject( "ActiveXperts.IPtoCountry" )         ' Create IPtoCountry object
WScript.Echo "ExpirationDate: " & objIPC.ExpirationDate

Host property

Type:

Number

Description:

Host name or IP address to be translated. The Query function translates this host/IP address to a country.

Example:

Set objIPC  = CreateObject( "ActiveXperts.IPtoCountry" )        ' Create IPtoCountry object
objIPC.Host = "www.activexperts.com"                            ' Host name (or IP address) 
                                                                ' that you want to resolve
objIPC.Query()                                                  ' Translate host/IP to country
WScript.Echo "Query, result: " & objIPC.LastError               ' Result of Query; 0 means: success
If objIPC.LastError <> 0 Then
   WScript.Quit
End If

WScript.Echo "Country (2 chars):" & objIPC.CountryCode          ' Two-character ISO 3166 country
                                                                    ' code
WScript.Echo "Country (3 chars):" & objIPC.CountryCodeEx        ' Three-character ISO 3166 country
                                                                    ' code
WScript.Echo "Country (full):"    & objIPC.CountryName          ' Full countryname

CountryCode property

Type:

String

Description:

Country associates with the given host or IP address. You need call Query to translate the host/IP address to a country. There are three different notations for a country; there's a property for each:

  • CountryCode - the two-character ISO 3166 country code. For instance: GB
  • CountryCodeEx - the three-character ISO 3166 country code. For instance: GBR
  • CountryName - the full country name. For instance: United Kingdom

For a list of possible country codes and country names, click here.

Example:

Set objIPC  = CreateObject( "ActiveXperts.IPtoCountry" )        ' Create IPtoCountry object
objIPC.Host = "www.activexperts.com"                            ' Host name (or IP address) 
                                                                ' that you want to resolve
objIPC.Query()                                                  ' Translate host/IP to country
WScript.Echo "Query, result: " & objIPC.LastError               ' Result of Query; 
                                                                ' 0 means: success
If objIPC.LastError <> 0 Then
   WScript.Quit
End If

WScript.Echo "Country (2 chars):" & objIPC.CountryCode          ' Two-character ISO 3166 
                                                                ' country code
WScript.Echo "Country (3 chars):" & objIPC.CountryCodeEx        ' Three-character ISO 3166 
                                                                ' country code
WScript.Echo "Country (full):"    & objIPC.CountryName          ' Full countryname

CountryCodeEx property

CountryName property

TodoSirp

LastError property

Type:

Number

Description:

Use it to check the result of your last function call. A zero indicates: success. Any non-zero value means an error.
The GetErrorDescription function provides the error description of an error code.
For a complete list of error codes, check out the following page: www.activexperts.com/support/errorcodes.

Example:

Set objIPC = CreateObject( "ActiveXperts.IPtoCountry" )         ' Create IPtoCountry object
...
objIPC.Query() 
WScript.Echo "LastError: " & objIPC.LastError

LogFile property

Type:

String

Description:

For troubleshooting purposes, you can specify a log file to trace all operations. By default, the 'LogFile' property holds the empty string. By assigning a valid filename to it, all operations will be written to this log file.

Example:

Set objIPC = CreateObject( "ActiveXperts.IPtoCountry" )         ' Create IPtoCountry object
objIPC.LogFile = "c:\file.log"
...
objIPC.Query() 
WScript.Echo "LastError: " & objIPC.LastError

12.3. Functions

Functions

Function Description
Clear Reset all properties to the default values
Query Translate an IP address (or host name) to a country
GetErrorDescription Get the description of the given error
Sleep Suspends the execution of the object for at least the specified interval
Activate Activate Software

Clear function

Description:

Reset all properties to their initial values. Use this function when you make consecutive calls to the Query function.

Parameters:

  • None

Return value:

Always 0.

Example:

Set objIPC  = CreateObject( "ActiveXperts.IPtoCountry" )        ' Create IPtoCountry object
...
objIPC.Query()                                              
objIPC.Clear()                                                  ' Clear all properties
objIPC.Query()

Query function

Description:

Translate an IP address (or host name) to a country.

Parameters:

  • None

Return value:

Always 0. Check LastError property to see if the function was completed successfully.

Example:

Set objIPC  = CreateObject( "ActiveXperts.IPtoCountry" )        ' Create IPtoCountry object
objIPC.Host = "www.activexperts.com"                            ' Host name (or IP address) 
                                                                ' that you want to resolve
objIPC.Query()                                                  ' Translate host/IP to country
WScript.Echo "Query, result: " & objIPC.LastError               ' Result of Query; 
                                                                ' 0 means: success
If objIPC.LastError <> 0 Then
   WScript.Quit
End If

WScript.Echo "Country (2 chars):" & objIPC.CountryCode          ' Two-character 
                                                                ' ISO 3166 country code
WScript.Echo "Country (3 chars):" & objIPC.CountryCodeEx        ' Three-character 
                                                                ' ISO 3166 country code
WScript.Echo "Country (full):"    & objIPC.CountryName          ' Full countryname
...

GetErrorDescription function

Description:

GetErrorDescription provides the error description of a given error code.

Parameters:

  • Error code

Return value:

The error description that is associated with the given error code.

Example:

Set objIPC  = CreateObject( "ActiveXperts.IPtoCountry" )
objIPC.Host = "www.activexperts.com"                        
objIPC.Query()                                                  ' Translate host/IP to country
WScript.Echo "Query, result: " & objIPC.LastError & _           ' Error code
       objIPC.GetErrorDescription( objIPC.LastError )           ' Error Description

Sleep function

Description:

This function can be used in your script anywhere you want. Suspends the execution of the object for at least the specified interval.

Parameters:

  • The number of milliseconds to suspend

Return value:

Always 0.

Example:

Set objIPC         = CreateObject( "ActiveXperts.IPtoCountry" ) ' Create IPtoCountry object
Set objConstants   = CreateObject( "ActiveXperts.ASConstants" ) ' Create constants object
...
objIPC.Sleep 500

Activate function

Description:

This function will activate the ActiveSocket product. A valid registrationcode is required.

Parameters:

  • The registration key
  • Persistent - this optional Boolean variable (default: True) specifies whether you want to add the registration key to the registry.
    If you pass 'True', you need to call the 'Activate' function only once for that computer.
    If you pass 'False', you need to call 'Activate' each time you create the object on that computer. This can be useful for customers who own a Distribution License of the product but do not want to show the registration key to their customers (see also here).

Return value:

Always 0. Check LastError property to see if the function was completed successfully.

Example:

Set objIPC = CreateObject( "ActiveXperts.IPtoCountry" )         ' Create IPtoCountry object
objIPC.Activate "xyz", True                                     ' Substitute xyz by your 
                                                                ' own registrationkey
' Pass True to make the activation persistent, so you need to call
' Activate only once. If you pass False, you need to call 
' Activate each time the product is started

13. Msn

13.1. Introduction

The Msn object is an instant messaging client object. It allows you to connect to Microsoft's Live Messenger Service and send a basic message to one or more MSN recipients. It provides basic chat features only, i.e. a subset of the features provided by Windows Live Messenger (formerly known as MSN Messenger) which is available for most Windows operating systems. The Msn object doesn't provide enhanced features like emoticons and file transfers.

The features provided by the ActiveSocket Msn object:

  • Connect to a Microsoft's Live Messenger Service; server is configurable (default: messenger.hotmail.com);
  • Login using a valid MSN account and MSN password;
  • Specify one or more MSN recipients;
  • Send a text message.

Here is a small example (in VBScript) to show how to use the Msn object to send an instant message to a remote MSN recipient:

Set objMsn = CreateObject( "ActiveXperts.Msn" )                 ' Create Msn object

objMsn.LogFile      = "C:\MSNLog.txt"                           ' Set Log File (optional)

objMsn.MsnAccount   = "mymeself@activexperts.com"               ' Set MSN Account
objMsn.MsnPassword  = "topsecret"                               ' Set MSN Password

objMsn.Message      = "Hello World !!!!"                        ' Set MSN Message
objMsn.AddRecipient "mycollegue1@activexperts.com"              ' Add recipient(s)
objMsn.AddRecipient "mycollegue2@activexperts.com"               

objMsn.Send                                                     ' Send the message

WScript.Echo "Result : " & objMsn.LastError                     ' Display the result

13.2. Properties

Properties

Property Type Read/Write Description
Version String Out Version of ActiveSocket
Build String Out Build of ActiveSocket
ExpirationDate String Out Expiration date of ActiveSocket
Server String In/Out The MSN server you want to connect to
ServerPort Number In/Out The MSN server IP port number
MsnAccount String In/Out The MSN account used to logon to the MSN server
MsnPassword String In/Out The MSN password used to logon to the MSN server
MsnDisplayName String In/Out The MSN display name used when logged on to the MSN server
Message String In/Out The MSN message to send to the remote MSN recipient(s)
LastError Number Out Result of last used function
LogFile String In/Out Log file; use it for troubleshooting purposes

Version property

Type:

String

Description:

Version information of ActiveSocket. This property is read-only; you cannot assign a value to it.

Example:

Set objMsn = CreateObject( "ActiveXperts.Msn" )                 ' Create Msn object
WScript.Echo  "Version: " & objMsn.Version                      ' Show version information

Build property

Type:

String

Description:

Build information of ActiveSocket. This property is read-only; you cannot assign a value to it.

Example:

Set objMsn = CreateObject( "ActiveXperts.Msn" )                 ' Create Msn object
WScript.Echo  "Build: " & objMsn.Build                          ' Show build information

ExpirationDate property

Type:

String

Description:

Expiration date of ActiveSocket. This property is read-only; you cannot assign a value to it.
Once you have registered the product, the property holds the empty string ("") value.

Example:

Set objMsn = CreateObject( "ActiveXperts.Msn" )                 ' Create Msn object
WScript.Echo "ExpirationDate: " & objMsn.ExpirationDate         ' Show expiration date

Server property

Type:

String

Description:

The MSN server you want to connect to. Default value: messenger.hotmail.com

Example:

Set objMsn = CreateObject( "ActiveXperts.Msn" )                 ' Create Msn object

objMsn.Server       = "messenger2.hotmail.com"                  ' Use messenger2.hotmail.com
objMsn.MsnAccount   = "mymeself@activexperts.com"        
objMsn.MsnPassword  = "topsecret"                    

objMsn.Message      = "Hello World !!!!"               
objMsn.AddRecipient "mycollegue1@activexperts.com"       

objMsn.Send                                                     ' Send the message

ServerPort property

Type:

Number

Description:

IP port of the MSN server you want to connect to. Default value: 1863.

Set objMsn = CreateObject( "ActiveXperts.Msn" )                 ' Create Msn object

objMsn.Server       = "messenger2.hotmail.com"                  ' Use messenger2.hotmail.com
objMsn.ServerPort   = 8063                                      ' Use port 8063
objMsn.MsnAccount   = "mymeself@activexperts.com"        
objMsn.MsnPassword  = "topsecret"                      

objMsn.Message      = "Hello World !!!!"               
objMsn.AddRecipient "mycollegue1@activexperts.com"      

objMsn.Send                                                     ' Send the message

MsnAccount property

Type:

String

Description:

The MSN account used to logon to the MSN server.

Example:

Set objMsn = CreateObject( "ActiveXperts.Msn" )                 ' Create Msn object

objMsn.MsnAccount   = "mymeself@activexperts.com"               ' Set MSN Account
objMsn.MsnPassword  = "topsecret"                               ' Set MSN Password

objMsn.Message      = "Hello World !!!!"                 
objMsn.AddRecipient "mycollegue1@activexperts.com"      

objMsn.Send                                                     ' Send the message

MsnPassword property

Type:

String

Description:

The MSN password used to logon to the MSN server.

Example:

Set objMsn = CreateObject( "ActiveXperts.Msn" )                 ' Create Msn object

objMsn.MsnAccount   = "mymeself@activexperts.com"               ' Set MSN Account
objMsn.MsnPassword  = "topsecret"                               ' Set MSN Password

objMsn.Message      = "Hello World !!!!"                  
objMsn.AddRecipient "mycollegue1@activexperts.com"       

objMsn.Send                                                     ' Send the message

MsnDisplayName property

Type:

String

Description:

The friendly name that will be shown to the remote MSN users. If omitted, the MSN Account is displayed.

Example:

Set objMsn = CreateObject( "ActiveXperts.Msn" )                 ' Create Msn object

objMsn.MsnAccount   = "mymeself@activexperts.com"         
objMsn.MsnPassword  = "topsecret"                          
objMsn.MsnDisplayName = "Me Myself"                             ' Set MSN Display Name

objMsn.Message      = "Hello World !!!!"                 
objMsn.AddRecipient "mycollegue1@activexperts.com"     

objMsn.Send                                                     ' Send the message

Message property

Type:

String

Description:

The Message text that to send to the remote recipients. The maximum length of a message is 1664 characters.

Example:

Set objMsn = CreateObject( "ActiveXperts.Msn" )                 ' Create Msn object

objMsn.MsnAccount   = "mymeself@activexperts.com"         
objMsn.MsnPassword  = "topsecret"                         
objMsn.MsnDisplayName = "Me Myself"                        

objMsn.Message      = "Hello World !!!!"                        ' Set Message text
objMsn.AddRecipient "mycollegue1@activexperts.com"       

objMsn.Send                                                     ' Send the message

LastError property

Type:

Number

Description:

Use it to check the result of your last function call. A zero indicates: success. Any non-zero value means an error.
The GetErrorDescription function provides the error description of an error code.
For a complete list of error codes, check out the following page: www.activexperts.com/support/errorcodes.

Example:

Set objMsn = CreateObject( "ActiveXperts.Msn" )            ' Create Msn object      
...
objMsn.Send                                                ' Send the message
WScript.Echo objMsn.LastError                              ' Display the result of the
                                                           ' Send function

LogFile property

Type:

String

Description:

For troubleshooting purposes, you can specify a log file to trace all operations. By default, the 'LogFile' property holds the empty string. By assigning a valid filename to it, all operations will be written to this log file.

Example:

Set objMsn = CreateObject( "ActiveXperts.Msn" )            ' Create Msn object      
objLogFile = "c:\msn.log"                                  ' Set log file 
...
objMsn.Send                                                ' Send the message
WScript.Echo objMsn.LastError                              ' Display the result of the
                                                           ' Send function

13.3. Functions

Functions

Function Description
Clear Reset all properties to the default values
AddRecipient Add an MSN recipient
Send Send the MSN message to the remote MSN recipient(s)
GetErrorDescription Get the description of the given error
Activate Activate Software

Clear function

Description:

Reset all properties to their initial values. Use this function when you make consecutive calls to the Send function.

Parameters:

  • None

Return value:

Always 0.

Example:

Set objMsn  = CreateObject( "ActiveXperts.Msn" )           ' Create Msn object
...
objMsn.Send()                                              
objMsn.Clear()                                             ' Clear all properties
objMsn.Send()

AddRecipient function

Description:

Add an MSN recipient. You can add multiple recipients, i.e. call the AddRecipient function multiple times.

Parameters:

  • The MSN address of the remote MSN recipient

Return value:

Always 0. Check LastError property to see if the function was completed successfully.

Example:

Set objMsn = CreateObject( "ActiveXperts.Msn" )            ' Create Msn object

objMsn.Server       = "messenger2.hotmail.com"            
objMsn.MsnAccount   = "mymeself@activexperts.com"         
objMsn.MsnPassword  = "topsecret"                          

objMsn.Message      = "Hello World !!!!"                   
objMsn.AddRecipient "mycollegue1@activexperts.com"         ' Add recipient(s)
objMsn.AddRecipient "mycollegue2@activexperts.com"               

objMsn.Send                                                ' Send the message

WScript.Echo "Result : " & objMsn.LastError                ' Display the result

Send function

Description:

Send the MSN message to the remote MSN recipient(s).

Parameters:

  • None

Return value:

Always 0. Check LastError property to see if the function was completed successfully.

Example:

Set objMsn = CreateObject( "ActiveXperts.Msn" )            ' Create Msn object

objMsn.Server       = "messenger2.hotmail.com"            
objMsn.MsnAccount   = "mymeself@activexperts.com"         
objMsn.MsnPassword  = "topsecret"                          

objMsn.Message      = "Hello World !!!!"                   
objMsn.AddRecipient "mycollegue1@activexperts.com" 

objMsn.Send                                                ' Send the message

WScript.Echo "Result : " & objMsn.LastError

GetErrorDescription function

Description:

GetErrorDescription provides the error description of a given error code.

Parameters:

  • Error code

Return value:

The error description that is associated with the given error code.

Example:

Set objMsn = CreateObject( "ActiveXperts.Msn" )            ' Create Msn object
...
objMsn.Send                                                ' Send the message
WScript.Echo "Result : " & objMsn.LastError & _
  " (" & objMsn.GetErrorDescription ( objMsn.LastError ) & ")"

Activate function

Description:

This function will activate the ActiveSocket product. A valid registrationcode is required.

Parameters:

  • The registration key
  • Persistent - this optional Boolean variable (default: True) specifies whether you want to add the registration key to the registry.
    If you pass 'True', you need to call the 'Activate' function only once for that computer.
    If you pass 'False', you need to call 'Activate' each time you create the object on that computer. This can be useful for customers who own a Distribution License of the product but do not want to show the registration key to their customers (see also here).

Return value:

Always 0. Check LastError property to see if the function was completed successfully.

Example:

Set objMsn = CreateObject( "ActiveXperts.Msn" )                 ' Create Msn object
objMsn.Activate "xyz", True            ' Substitute xyz by your own registrationkey
' Pass True to make the activation persistent, so you need to call
' Activate only once. If you pass False, you need to call 
' Activate each time the product is started

14. Ntp

14.1. Introduction

The Network Time Protocol (NTP) has been developed to address the issue of providing accurate and synchronized time across the Internet. The protocol itself has been in development since 1985 and has therefore reached a fairly mature status. The latest stable version of NTP is version 3 and described in RFC-1305 the latest testing version is NTP version 4.

The Network Time Protocol aims to synchronize a systems clock to Coordinated Universal Time (UTC). UTC is a development of Greenwich Mean Time (GMT). GMT is based on the rotation of the earth while UTC is based on the standard length of a second determined from quantum phenomena, but both use the Greenwich time zone as the zero offset.

NTP uses a augmented hierarchical client-server topology. A small number of servers distribute time to a larger number of clients which can simultaneously act as servers to further clients. The top level clients are referred to as stratum 1 servers and their clients are termed as being at stratum 2. Clients of a stratum 2 server are at stratum 3 and so on. The stratum 1 servers are synchronized to radio clocks which receive time signals from national time standards such as the MSF signal provided by the NPL broadcast from Rugby or the GPS time signal provided by the Global Positioning System. The radio clocks themselves are termed stratum 0 servers.

The ActiveSocket Ntp object enables you to add Ntp functionality to your program. Here is a small example (in VBScript) to show how to use the Ntp object: The following sample (in VBScript) runs the '/bin/ls' command on host '192.168.1.10', and will timeout when the script takes more than 5000 milliseconds:

objNtp = CreateObject( "ActiveXperts.Ntp" )    ' Create a new Ntp instance
objNtp.GetTime "mytimeserver.domain.dom"       ' Retrieve time from this time server
If( objNtp.LastError = 0 ) Then
  WScript.Echo "Time retrieved successfully, the results are:"
  WScript.Echo "Year : "   & objNtp.Year
  WScript.Echo "Month : "  & objNtp.Month
  WScript.Echo "Day : "    & objNtp.Day
  WScript.Echo "Hour : "   & objNtp.Hour
  WScript.Echo "Minute : " & objNtp.Minute
  WScript.Echo "Second : " & objNtp.Second
End If

14.2. Properties

Properties

Property Type Read/Write Description
Version String Out Version number of ActiveSocket
Build String Out Display build information of ActiveSocket
ExpirationDate String Out Expiration date of ActiveSocket
LastError Number Out Result of the last called function
Year Number Out The year, as provided by the NTP server
Month Number Out The month, as provided by the NTP server
Day Number Out The day, as provided by the NTP server
Hour Number Out The hour, as provided by the NTP server
Minute Number Out The minute, as provided by the NTP server
Second Number Out The second, as provided by the NTP server
LocalOffsetSeconds Number Out The offset (in seconds) between the local computer and the Network Time Server

Version property

Type:

String

Description:

Version information of ActiveSocket. This property is read-only; you cannot assign a value to it.

Example:

Set objNtp = CreateObject( "ActiveXperts.Ntp" )            ' Create Ntp object
WScript.Echo  "Version: " & objNtp.Version

Build property

Type:

String

Description:

Build information of ActiveSocket. This property is read-only; you cannot assign a value to it.

Example:

Set objNtp = CreateObject( "ActiveXperts.Ntp" )           ' Create Ntp object
WScript.Echo  "Build: " & objNtp.Build

ExpirationDate property

Type:

String

Description:

Expiration date of ActiveSocket. This property is read-only; you cannot assign a value to it.
Once you have registered the product, the property holds the empty string ("") value.

Example:

Set objNtp = CreateObject( "ActiveXperts.Ntp" )            ' Create Ntp object
WScript.Echo "ExpirationDate: " & objNtp.ExpirationDate

LastError property

Type:

Number

Description:

The result of a previous called function. Use it to check the result of your last function call. A zero indicates: success. Any non-zero value means an error.
The GetErrorDescription function provides the error description of an error code.
For a complete list of error codes, check out the following page: www.activexperts.com/support/errorcodes.

Example:

objNtp = CreateObject( "ActiveXperts.Ntp" )                ' Create a new Ntp instance
objNtp.GetTime "timeserver01.domain.dom"                   ' Retrieve time
WScript.Echo "LastError: " & objNtp.LastError

Year property

Type:

Number

Description:

After a successful call to the GetTime function, the 'Year', 'Month', 'Day', 'Hour', 'Minute' and 'Second' properties are assigned with the time information that was retrieved from the Network Time Server. The properties are read-only; you cannot assign a value to it.

Example:

objNtp = CreateObject( "ActiveXperts.Ntp" )                ' Create a new Ntp instance
objNtp.GetTime( "timeserver.domain.dom" )                  ' Retrieve time
if( objNtp.LastError = 0 ) Then
  WScript.Echo "Year : " & objNtp.Year
  WScript.Echo "Month : " & objNtp.Month
  WScript.Echo "Day : " & objNtp.Day
  WScript.Echo "Hour : " & objNtp.Hour
  WScript.Echo "Minute : " & objNtp.Minute
  WScript.Echo "Second : " & objNtp.Second
End If

Month property

Type:

Number

Description:

After a successful call to the GetTime function, the 'Year', 'Month', 'Day', 'Hour', 'Minute' and 'Second' properties are assigned with the time information that was retrieved from the Network Time Server. The properties are read-only; you cannot assign a value to it.

Example:

objNtp = CreateObject( "ActiveXperts.Ntp" )                ' Create a new Ntp instance
objNtp.GetTime( "timeserver.domain.dom" )                  ' Retrieve time
if( objNtp.LastError = 0 ) Then
  WScript.Echo "Year : " & objNtp.Year
  WScript.Echo "Month : " & objNtp.Month
  WScript.Echo "Day : " & objNtp.Day
  WScript.Echo "Hour : " & objNtp.Hour
  WScript.Echo "Minute : " & objNtp.Minute
  WScript.Echo "Second : " & objNtp.Second
End If

Day property

Type:

Number

Description:

After a successful call to the GetTime function, the 'Year', 'Month', 'Day', 'Hour', 'Minute' and 'Second' properties are assigned with the time information that was retrieved from the Network Time Server. The properties are read-only; you cannot assign a value to it.

Example:

objNtp = CreateObject( "ActiveXperts.Ntp" )                ' Create a new Ntp instance
objNtp.GetTime( "timeserver.domain.dom" )                  ' Retrieve time
if( objNtp.LastError = 0 ) Then
  WScript.Echo "Year : " & objNtp.Year
  WScript.Echo "Month : " & objNtp.Month
  WScript.Echo "Day : " & objNtp.Day
  WScript.Echo "Hour : " & objNtp.Hour
  WScript.Echo "Minute : " & objNtp.Minute
  WScript.Echo "Second : " & objNtp.Second
End If

Hour property

Type:

Number

Description:

After a successful call to the GetTime function, the 'Year', 'Month', 'Day', 'Hour', 'Minute' and 'Second' properties are assigned with the time information that was retrieved from the Network Time Server. The properties are read-only; you cannot assign a value to it.

Example:

objNtp = CreateObject( "ActiveXperts.Ntp" )                ' Create a new Ntp instance
objNtp.GetTime( "timeserver.domain.dom" )                  ' Retrieve time
if( objNtp.LastError = 0 ) Then
  WScript.Echo "Year : " & objNtp.Year
  WScript.Echo "Month : " & objNtp.Month
  WScript.Echo "Day : " & objNtp.Day
  WScript.Echo "Hour : " & objNtp.Hour
  WScript.Echo "Minute : " & objNtp.Minute
  WScript.Echo "Second : " & objNtp.Second
End If

Minute property

Type:

Number

Description:

After a successful call to the GetTime function, the 'Year', 'Month', 'Day', 'Hour', 'Minute' and 'Second' properties are assigned with the time information that was retrieved from the Network Time Server. The properties are read-only; you cannot assign a value to it.

Example:

objNtp = CreateObject( "ActiveXperts.Ntp" )                ' Create a new Ntp instance
objNtp.GetTime( "timeserver.domain.dom" )                  ' Retrieve time
if( objNtp.LastError = 0 ) Then
  WScript.Echo "Year : " & objNtp.Year
  WScript.Echo "Month : " & objNtp.Month
  WScript.Echo "Day : " & objNtp.Day
  WScript.Echo "Hour : " & objNtp.Hour
  WScript.Echo "Minute : " & objNtp.Minute
  WScript.Echo "Second : " & objNtp.Second
End If

Second property

Type:

Number

Description:

After a successful call to the GetTime function, the 'Year', 'Month', 'Day', 'Hour', 'Minute' and 'Second' properties are assigned with the time information that was retrieved from the Network Time Server. The properties are read-only; you cannot assign a value to it.

Example:

objNtp = CreateObject( "ActiveXperts.Ntp" )                ' Create a new Ntp instance
objNtp.GetTime( "timeserver.domain.dom" )                  ' Retrieve time
if( objNtp.LastError = 0 ) Then
  WScript.Echo "Year : " & objNtp.Year
  WScript.Echo "Month : " & objNtp.Month
  WScript.Echo "Day : " & objNtp.Day
  WScript.Echo "Hour : " & objNtp.Hour
  WScript.Echo "Minute : " & objNtp.Minute
  WScript.Echo "Second : " & objNtp.Second
End If

LocalOffsetSeconds property

Type:

Number

Description:

After a successful call to the GetTime function, the 'LocalOffsetSeconds' holds the offset (in seconds) between the NTP server time and the local computer time. Use this value to check if your local computer time is in sync with the NTP server's time. The property is read-only; you cannot assign a value to it.

Example:

objNtp = CreateObject( "ActiveXperts.Ntp" )                ' Create a new Ntp instance
objNtp.GetTime( "timeserver.domain.dom" )                  ' Retrieve time
If( objNtp.LastError = 0 ) Then
  WScript.Echo "Time offset : " & objNtp.LocalOffsetSeconds & " seconds"
End If

14.3. Functions

Functions

Function Description
Clear Reset all properties to the default values
GetTime Query the NTP server to retrieve date and time
GetErrorDescription Get the description of the given error
Sleep Suspends the execution of the object for at least the specified interval
Activate Activate Software

Clear function

Description:

Resets all properties to the initial values. Use this function when you make consecutive calls to the GetTime function. It sets Year, Month, Day, Hour, Minute and Second to 0.

Parameters:

  • None

Return value:

Always 0.

Example:

objNtp = CreateObject( "ActiveXperts.Ntp" )                ' Create a new Ntp instance
objNtp.GetTime( "timeserver.domain.dom" )                  ' Retrieve time
...
objNtp.Clear()
objNtp.GetTime( "timeserver02.domain.dom" )
...
objNtp.Clear()
objNtp.GetTime( "timeserver03.domain.dom" )
...

GetTime function

Description:

Query the network time server and retrieve its date and time.

Parameters:

  • None

Return value:

Always 0. Check LastError property to see if the function was completed successfully.

Example:

objNtp = CreateObject( "ActiveXperts.Ntp" )                ' Create a new Ntp instance
objNtp.GetTime( "timeserver.domain.dom" )                  ' Retrieve time
If( objNtp.LastError = 0 ) Then
  WScript.Echo "Year : "   & objNtp.Year
  WScript.Echo "Month : "  & objNtp.Month
  WScript.Echo "Day : "    & objNtp.Day
  WScript.Echo "Hour : "   & objNtp.Hour
  WScript.Echo "Minute : " & objNtp.Minute
  WScript.Echo "Second : " & objNtp.Second
End If

GetErrorDescription function

Description:

GetErrorDescription provides the error description of a given error code.

Parameters:

  • Error code

Return value:

The error description that is associated with the given error code.

Example:

Set objNtp = CreateObject("ActiveXperts.Ntp")              ' Create a new Ntp instance
objNtp.GetTime( "invalidtimeserver.com" )                  ' Retrieve time
WScript.Echo "Error description: " & objNtp.GetErrorDescription( objNtp.LastError )

Sleep function

Description:

This function can be used in your script anywhere you want. Suspends the execution of the object for at least the specified interval.

Parameters:

  • The number of milliseconds to suspend

Return value:

Always 0.

Example:

Set objNtp         = CreateObject( "ActiveXperts.Ntp" )          ' Create Ntp object
Set objConstants   = CreateObject( "ActiveXperts.ASConstants" )  ' Create constants object
...
objNtp.Sleep 500

Activate function

Description:

This function activates the ActiveSocket product. A valid registration code is required.

Parameters:

  • The registration key
  • Persistent - this optional Boolean variable (default: True) specifies whether you want to add the registration key to the registry.
    If you pass 'True', you need to call the 'Activate' function only once for that computer.
    If you pass 'False', you need to call 'Activate' each time you create the object on that computer. This can be useful for customers who own a Distribution License of the product but do not want to show the registration key to their customers (see also here)

Return value:

Always 0. Check LastError property to see if the function was completed successfully.

Example:

Set objNtp         = CreateObject( "ActiveXperts.Ntp" )       ' Create Ntp object
objNtp.Activate "xyz", True      ' Substitute xyz by your own registrationkey
' Pass True to make the activation persistent, so you need to call
' Activate only once. If you pass False, you need to call
' Activate each time the product is started

15. RADIUS

15.1. Introduction

RADIUS (Remote Authentication Dial In User Service) is a networking protocol that provides centralized authentication and authorization management for computers to connect and use a network service. It was originally developed by Livingston Enterprises in 1991 as an access server authentication and accounting protocol and later brought into the IETF standards where it is described in RCF 2865 and RCF 2866.

RADIUS is a client/server protocol that uses UDP as a transport. A RADIUS server is usually a background process running on a UNIX or Windows NT server. The RADIUS component in activesocket currently only supports authenticating users. This means that the activesocket RADIUS implementation can be used to check against a RADIUS server whether or not a user has access to a network.

The following sample (in VBScript) tests if the user 'Test' has access to a network, and will timeout when the script takes more than 5000 milliseconds:

Set objRadius = CreateObject("ActiveXperts.Radius")             ' Create a RADIUS instance

objRadius.CheckAccess "192.168.1.10", "test", "password", _ 
  "secret"                                                      ' Check if the test user is 
                                                                ' authorized
If objRadius.LastError <> 0 Then
  WScript.Echo "Error: "  & objRadius.LastError
  WScript.Echo "Description "  & objRadius.GetErrorDescription(objRadius.LastError)  
  WScript.Quit 1
End If

WScript.Echo "Ready."

15.2. Properties

Properties

Property Type Read/Write Description
Version String Out Version number of ActiveSocket
Build String Out Display build information of ActiveSocket
ExpirationDate String Out Expiration date of ActiveSocket
LastError Number Out Result of the last called function
Timeout Number In/Out Specifies the number of milliseconds until the command times out

Version property

Type:

String

Description:

Version information of ActiveSocket. This property is read-only; you cannot assign a value to it.

Example:

Set objRADIUS = CreateObject( "ActiveXperts.RADIUS" )            ' Create RADIUS object
WScript.Echo  "Version: " & objRADIUS.Version

Build property

Type:

String

Description:

Build information of ActiveSocket. This property is read-only; you cannot assign a value to it.

Example:

Set objRADIUS = CreateObject( "ActiveXperts.RADIUS" )           ' Create RADIUS object
WScript.Echo  "Build: " & objRADIUS.Build

ExpirationDate property

Type:

String

Description:

Expiration date of ActiveSocket. This property is read-only; you cannot assign a value to it.
Once you have registered the product, the property holds the empty string ("") value.

Example:

Set objRADIUS = CreateObject( "ActiveXperts.RADIUS" )            ' Create RADIUS object
WScript.Echo "ExpirationDate: " & objRADIUS.ExpirationDate

LastError property

Type:

Number

Description:

The result of a previous called function. Use it to check the result of your last function call. A zero indicates: success. Any non-zero value means an error.
The GetErrorDescription function provides the error description of an error code.
For a complete list of error codes, check out the following page: www.activexperts.com/support/errorcodes.

Example:

Set objRADIUS           = CreateObject("ActiveXperts.RADIUS")    ' Create an RADIUS instance
...
objRADIUS.CheckAccess "192.168.1.10", "test", "password", "secret"
WScript.Echo "LastError: " & objRADIUS.LastError

Timeout property

Type:

Number

Description:

Specifies the number of milliseconds before the command will time out.

Example:

Set objRADIUS           = CreateObject("ActiveXperts.RADIUS")   ' Create an RADIUS 
                                                                ' instance
objRADIUS.TimeOut       = 6000                                  ' Timeout after 6000 
                                                                ' milliseconds
objRADIUS.CheckAccess "192.168.1.10", "test", "password", "secret"

15.3. Functions

Functions

Function Description
Clear Reset all properties to the default values
CheckAccess Check if a user would be authorized
GetErrorDescription Get the description of the given error
Sleep Suspends the execution of the object for at least the specified interval
Activate Activate Software

Clear function

Description:

Reset all properties to the initial values. Use this function when you make consecutive calls to the CheckAccess function. It resets all properties

Parameters:

  • None

Return value:

Always 0.

Example:

Set objRADIUS = CreateObject("ActiveXperts.RADIUS")             ' Create an RADIUS instance
...
objRADIUS.Timeout         = 10000
objRADIUS.CheckAccess "192.168.1.10", "test", "password", "secret"
objRADIUS.Clear                                                 ' Resets properties
' Set new property values
...
objRADIUS.Timeout         = 8000
objRADIUS.CheckAccess "192.168.1.10", "test", "password", "secret"
objRADIUS.Clear
...

CheckAccess function

Sirp

GetErrorDescription function

Description:

GetErrorDescription provides the error description of a given error code.

Parameters:

  • Error code

Return value:

The error description that is associated with the given error code.

Example:

Set objRADIUS           = CreateObject("ActiveXperts.RADIUS")  ' Create an RADIUS instance
objRADIUS.CheckAccess "192.168.1.10", "test", "password", "secret"
WScript.Echo "Run: result = " & objRADIUS.LastError

Sleep function

ToDo

Activate function

Description:

This function activates the ActiveSocket product. A valid registration code is required.

Parameters:

  • The registration key
  • Persistent - this optional Boolean variable (default: True) specifies whether you want to add the registration key to the registry.
    If you pass 'True', you need to call the 'Activate' function only once for that computer.
    If you pass 'False', you need to call 'Activate' each time you create the object on that computer. This can be useful for customers who own a Distribution License of the product but do not want to show the registration key to their customers (see also here)

Return value:

Always 0. Check LastError property to see if the function was completed successfully.

Example:

Set objRADIUS         = CreateObject( "ActiveXperts.RADIUS" )       ' Create RADIUS object
objRADIUS.Activate "xyz", True                  ' Substitute xyz by your own registrationkey
' Pass True to make the activation persistent, so you need to call
' Activate only once. If you pass False, you need to call
' Activate each time the product is started

16. Rsh

16.1. Introduction

Rsh executes a command on a host. The remote hosts must run the Rsh daemon.
An Rsh client utility is shipped with most operating systems these days. This Rsh command line utility copies its standard input to the remote command, the standard output of the remote command to its standard output, and the standard error of the remote command to its standard error. Interrupt, quit and terminate signals are propagated to the remote command; rsh normally terminates when the remote command does.

The ActiveSocket Rsh object has the same functionality as the Rsh command-line utility, except that it has no user interface by itself: standard error and standard output are not copied to the console, but are copied to the corresponding object properties (StdErr and StdOut) instead.

The following sample (in VBScript) runs the '/bin/ls' command on host '192.168.1.10', and will timeout when the script takes more than 5000 milliseconds:

Set objRsh           = CreateObject("ActiveXperts.Rsh")         ' Create an Rsh instance
objRsh.Host          = "192.168.1.10"                           ' Hostname or IP address of  
                                                                ' remote UNIX/LINUX machine
objRsh.UserName      = "root"                                   ' Login as 'root'
objRsh.Password      = "topsecret"                              ' Use a password to login
objRsh.Command       = "/bin/ls"                                ' Command to execute
objRsh.ScriptTimeOut = 5000                                     ' Time-out (in milliseconds)
objRsh.Run                                                      ' Execute the command now
WScript.Echo "Run: result = " & objRsh.LastError 
If objRsh.LastError <> 0 Then
  WScript.Echo "Error "  & objRsh.LastError
End If
' YES, command has completed
WScript.Echo "StdErr: " & objRsh.StdErr                         ' Print Standard Output
WScript.Echo "StdOut: " & objRsh.StdOut                         ' Print Standard Error

WScript.Echo "Ready."

16.2. Properties

Properties

Property Type Read/Write Description
Version String Out Version number of ActiveSocket
Build String Out Display build information of ActiveSocket
ExpirationDate String Out Expiration date of ActiveSocket
LastError Number Out Result of the last called function
Command String In/Out Specifies the command to run on the remote host
Host String In/Out Specifies the host on which to run the command
UserName String In/Out Specifies the user name to use on the remote host. If omitted, the logged on user name is used.
ScriptTimeOut Number In/Out Specifies the number of milliseconds until the command times out
StdErr String Out The Rsh 'Run' function copies its standard error to this property
StdOut String Out The Rsh 'Run' function copies its standard output to this property

Version property

Type:

String

Description:

Version information of ActiveSocket. This property is read-only; you cannot assign a value to it.

Example:

Set objRsh = CreateObject( "ActiveXperts.Rsh" )                 ' Create Rsh object
WScript.Echo  "Version: " & objRsh.Version

Build property

Type:

String

Description:

Build information of ActiveSocket. This property is read-only; you cannot assign a value to it.

Example:

Set objRsh = CreateObject( "ActiveXperts.Rsh" )                ' Create Rsh object
WScript.Echo  "Build: " & objRsh.Build

ExpirationDate property

Type:

String

Description:

Expiration date of ActiveSocket. This property is read-only; you cannot assign a value to it.
Once you have registered the product, the property holds the empty string ("") value.

Example:

Set objRsh = CreateObject( "ActiveXperts.Rsh" )                 ' Create Rsh object
WScript.Echo "ExpirationDate: " & objRsh.ExpirationDate

LastError property

Type:

Number

Description:

The result of a previous called function. Use it to check the result of your last function call. A zero indicates: success. Any non-zero value means an error.
The GetErrorDescription function provides the error description of an error code.
For a complete list of error codes, check out the following page: www.activexperts.com/support/errorcodes.

Example:

Set objRsh           = CreateObject("ActiveXperts.Rsh")         ' Create an Rsh instance
...
objRsh.Run
WScript.Echo "LastError: " & objRsh.LastError

Command property

Type:

String

Description:

Specifies the command to run on the remote host.

Example:

Set objRsh           = CreateObject("ActiveXperts.Rsh")         ' Create an Rsh instance
objRsh.Command       = "/bin/ls"
objRsh.Host          = "server01.domain.dom"
objRsh.Run

Host property

Type:

String

Description:

Specifies the host on which to run the command.

Example:

Set objRsh           = CreateObject("ActiveXperts.Rsh")         ' Create an Rsh instance
objRsh.Host          = "server01.domain.dom"
objRsh.Command       = "/bin/ls"
objRsh.Run

UserName property

Type:

String

Description:

Specifies the user name to use on the remote host. If omitted, the logged on user name is used.

Example:

Set objRsh           = CreateObject("ActiveXperts.Rsh")         ' Create an Rsh instance
objRsh.Host          = "server01.domain.dom"
objRsh.Command       = "/bin/ls"
objRsh.UserName      = "mjohnson"
objRsh.Run

ScriptTimeOut property

Type:

Number

Description:

Specifies the number of milliseconds before the command will time out.

Example:

Set objRsh           = CreateObject("ActiveXperts.Rsh")         ' Create an Rsh instance
objRsh.Host          = "server01.domain.dom"
objRsh.Command       = "/bin/ls"
objRsh.ScriptTimeOut = 6000                                     ' Timeout after 6000 
                                                                ' milliseconds
objRsh.Run

StdErr property

Type:

String

Description:

Rsh connects to the command. Rsh copies its standard error of the remote command to the 'StdErr' property.

Example:

Set objRsh           = CreateObject("ActiveXperts.Rsh")         ' Create an Rsh instance
...
objRsh.Run
If( objRsh.LastError = 0 ) Then
  WScript.Echo "StdErr: " & objRsh.StdErr
End

StdOut property

Type:

String

Description:

Rsh connects to the command. Rsh copies its standard out of the remote command to the 'StdOut' property.

Example:

Set objRsh           = CreateObject("ActiveXperts.Rsh")         ' Create an Rsh instance
objRsh.Run
If( objRsh.LastError = 0 ) Then
  WScript.Echo "StdOut: " & objRsh.StdOut
End

16.3. Functions

Functions

Function Description
Clear Reset all properties to the default values
Run Run the command on the remote host
GetErrorDescription Get the description of the given error
Sleep Suspends the execution of the object for at least the specified interval
Activate Activate Software

Clear function

Description:

Reset all properties to the initial values. Use this function when you make consecutive calls to the Run function. It resets all properties

Parameters:

  • None

Return value:

Always 0.

Example:

 
Set objRsh = CreateObject("ActiveXperts.Rsh")                   ' Create an Rsh instance
...
objRsh.Run
objRsh.Clear                                                    ' Resets properties
' Set new property values
...
objRsh.Run
objRsh.Clear
...

Run function

Description:

Run the command on the remote host.

Parameters:

  • None

Return value:

Always 0. Check LastError property to see if the function was completed successfully.

Example:

Set objRsh           = CreateObject("ActiveXperts.Rsh")         ' Create an Rsh instance
objRsh.Host          = "192.168.1.10"
objRsh.Command       = "/bin/ls"
objRsh.Run
WScript.Echo "Run: result = " & objRsh.LastError

GetErrorDescription function

Description:

GetErrorDescription provides the error description of a given error code.

Parameters:

  • Error code

Return value:

The error description that is associated with the given error code.

Example:

Set objRsh           = CreateObject("ActiveXperts.Rsh")         ' Create an Rsh instance
objRsh.Host          = "192.168.1.10"
objRsh.Command       = "/bin/ls"
objRsh.Run
WScript.Echo "Run: result = " & objRsh.LastError

Sleep function

Description:

This function can be used in your script anywhere you want. Suspends the execution of the object for at least the specified interval.

Parameters:

  • The number of milliseconds to suspend

Return value:

Always 0.

Example:

Set objRsh         = CreateObject( "ActiveXperts.Rsh" )         ' Create Rsh object
Set objConstants   = CreateObject( "ActiveXperts.ASConstants" ) ' Create constants object
...
objRsh.Sleep 500

Activate function

Description:

This function activates the ActiveSocket product. A valid registration code is required.

Parameters:

  • The registration key
  • Persistent - this optional Boolean variable (default: True) specifies whether you want to add the registration key to the registry.
    If you pass 'True', you need to call the 'Activate' function only once for that computer.
    If you pass 'False', you need to call 'Activate' each time you create the object on that computer. This can be useful for customers who own a Distribution License of the product but do not want to show the registration key to their customers (see also here)

Return value:

Always 0. Check LastError property to see if the function was completed successfully.

Example:

Set objRsh         = CreateObject( "ActiveXperts.Rsh" )         ' Create Rsh object
objRsh.Activate "xyz", True                                     ' Substitute xyz by 
                                                                ' your own registrationkey
' Pass True to make the activation persistent, so you need to call
' Activate only once. If you pass False, you need to call
' Activate each time the product is started

17. Scp

17.1. Introduction

Scp (Secure Copy Protocol) is a way to securely transfer files between two computers using the SSH (Secure SHell) protocol.

The Secure Copy Protocol is the secure analog of the old UNIX RCP command. It is implemented as a part of the SSH system, which means that an SCP client can be used to copy to any file or files to or from a host which has an SSH server running and which has the SCP service enabled.

An SCP client can only be used to copy files. To list the contents of a remote directory or to query for remote file information either SSH or SFTP would be required. In most applications the SCP protocol is considered to be superseded by the more advanced SFTP protocol. However, in some implementations copying a file using an SCP implementation can have a performance advantage.

The ActiveSocket SCP implementation is based on the PuTTY SCP implementation.

When connecting to a remote host there are two ways to authenticate: by using a password or by using a 'private key'. When using a password to authenticate it is required that the host private key is known to the system. If the hosts private key is unknown to the system or if it was changed since the last connection the Scp object will return an error. To connect anyway and store the host key in the registry for future connections the 'AcceptHostKey' property can be set.

NOTE:

  • The ActiveSocket Scp object is not thread safe (A process can only have one active session). However, it is possible to run multiple processes with active sessions at once.

The following sample (in VBScript) copies the 'Smalltoken.file to the 'demo' users home directory on 192.168.1.10 using a password:

  Set objScp           = CreateObject("ActiveXperts.Scp")       ' Create an Scp instance
  objScp.Host          = "192.168.1.10"                         ' Hostname or IP address of 
                                                                ' remote UNIX/LINUX machine
  objScp.UserName      = "demo"                                 ' Login as 'demo'
  objScp.Password      = "topsecret"                            ' Use a password to login
  objScp.CopyToRemote "Smalltoken.file", "."                    ' Copy the file to the remote 
                                                                ' location
  WScript.Echo "Copy: result = " & objScp.LastError 
  If objScp.LastError <> 0 Then
    WScript.Echo "Error: "  & objScp.LastError
    If objScp.ProtocolError <> "" Then
      WScript.Echo "Protocol error: " & objScp.ProtocolError    
    End If
  End If
  ' YES, command has completed
  WScript.Echo "Ready."

The following sample (in VBScript) copies the 'Smalltoken.file to the 'demo' users home directory on 192.168.1.10 using a private key file:

  Set objScp           = CreateObject("ActiveXperts.Scp")       ' Create an Scp instance
  objScp.Host          = "192.168.1.10"                         ' Hostname or IP address of 
                                                                ' remote UNIX/LINUX machine
  objScp.UserName      = "demo"                                 ' Login as 'demo'
  objScp.PrivateKeyFile = "c:\files\privkey.ppk"                ' Use a private key file to 
                                                                ' login    
  objScp.CopyToRemote "Smalltoken.file", "."                    ' Copy the file to the remote 
                                                                ' location
  WScript.Echo "Copy: result = " & objScp.LastError 
  If objScp.LastError <> 0 Then
    WScript.Echo "Error: "  & objScp.LastError
    If objScp.ProtocolError <> "" Then
      WScript.Echo "Protocol error: " & objScp.ProtocolError    
    End If
  End If
  ' YES, command has completed
  WScript.Echo "Ready."

17.2. Properties

Properties

Property Type Read/Write Description
Version String Out Version number of ActiveSocket
Build String Out Display build information of ActiveSocket
ExpirationDate String Out Expiration date of ActiveSocket
LastError Number Out Result of the last called function
ProtocolError String Out If the last called function triggered a protocol error. This property will contain more information.
Host String In/Out Specifies the host to which or from which should be copied
Port Number In/Out TCP port number to identify a (remote) SSH/SCP daemon. Default: 22
UserName String In/Out Specifies the user name to use on the remote host
Password String In/Out Specifies the password to use on the remote host. If this property is left blank the 'PrivateKeyFile' property will be used to authenticate.
PrivateKeyFile String In/Out Specifies the private key file to logon to the remote host. If this property is left blank the 'Password' property will be used to authenticate.
Recursive Boolean In/Out Specifies whether to recursively copy directories
Compression Boolean In/Out Specifies whether to use compression when transferring files
AcceptHostKey Boolean In/Out Specifies whether to accept an unknown or changed host key
HostFingerprint String Out The Scp 'CopyToRemote' and 'CopyToLocal' functions copy the host key fingerprint to this property
LogFile Boolean In/Out Log file; use it for troubleshooting purposes

Version property

Type:

String

Description:

Version information of ActiveSocket. This property is read-only; you cannot assign a value to it.

Example:

Set objScp = CreateObject( "ActiveXperts.Scp" )                 ' Create Scp object
WScript.Echo  "Version: " & objScp.Version

Build property

Type:

String

Description:

Build information of ActiveSocket. This property is read-only; you cannot assign a value to it.

Example:

Set objScp = CreateObject( "ActiveXperts.Scp" )                 ' Create Scp object
WScript.Echo  "Build: " & objScp.Build

ExpirationDate property

Type:

String

Description:

Expiration date of ActiveSocket. This property is read-only; you cannot assign a value to it.
Once you have registered the product, the property holds the empty string ("") value.

Example:

Set objScp = CreateObject( "ActiveXperts.Scp" )                 ' Create Scp object
WScript.Echo "ExpirationDate: " & objScp.ExpirationDate

LastError property

Type:

Number

Description:

The result of a previous called function. Use it to check the result of your last function call. A zero indicates: success. Any non-zero value means an error.
The GetErrorDescription function provides the error description of an error code.
For a complete list of error codes, check out the following page: www.activexperts.com/support/errorcodes.

Example:

Set objScp           = CreateObject("ActiveXperts.Scp")         ' Create an Scp instance
...
objScp.CopyToRemote "Smalltoken.file", "."
WScript.Echo "LastError: " & objScp.LastError

ProtocolError property

Type:

String

Description:

If the last called function triggered a protocol error. This property will contain more information. The protocol error string is usually triggered and formulated into an error description at the remote host.

Example:

Set objScp           = CreateObject("ActiveXperts.Scp")         ' Create an Scp instance
...
objScp.CopyToRemote "Smalltoken.file", "."
If objScp.LastError <> 0 Then
  WScript.Echo "Error: "  & objScp.LastError
  If objScp.ProtocolError <> "" Then
    WScript.Echo "Protocol error: " & objScp.ProtocolError    
  End If
End If

Host property

Type:

String

Description:

Specifies the host onto or from which the files will be copied.

Example:

Set objScp           = CreateObject("ActiveXperts.Scp")         ' Create an Scp instance
objScp.Host          = "server01.domain.dom"
...
objScp.CopyToRemote "Smalltoken.file", "."

Port property

Type:

Number

Description:

TCP port number to identify a remote SSH/SCP daemon. If you don't specify the 'Port' property, port 22 (default SCP port) is used.

Example:

Set objScp           = CreateObject("ActiveXperts.Scp")         ' Create an Scp instance
objScp.Host          = "server01.domain.dom"
objScp.Port          = 8022                                     ' Use port 8022 instead of 22
...
objScp.CopyToRemote "Smalltoken.file", "."

UserName property

Type:

String

Description:

Specifies the user name to use on the remote host. You must also specify either a Private Key to logon to the machine.

Example:

Set objScp           = CreateObject("ActiveXperts.Scp")         ' Create an Scp instance
objScp.Host          = "server01.domain.dom"
objScp.UserName      = "mjohnson"
objScp.Password      = "topsecret"
objScp.CopyToRemote "Smalltoken.file", "."

Password property

Type:

String

Description:

Specifies the password to use on the remote host. If you do not use a password, you must use a Private Key to logon to the machine.

Example:

Set objScp           = CreateObject("ActiveXperts.Scp")         ' Create an Scp instance
objScp.Host          = "server01.domain.dom"
objScp.UserName      = "mjohnson"
objScp.Password      = "topsecret"
objScp.CopyToRemote "Smalltoken.file", "."

PrivateKeyFile property

Type:

String

Description:

Specifies the private key file to use on the remote host. If you do not use a private key, you must use a Password to logon to the machine.

Example:

Set objScp           = CreateObject("ActiveXperts.Scp")         ' Create an Scp instance
objScp.Host          = "server01.domain.dom"
objScp.UserName      = "mjohnson"
objScp.PrivateKeyFile= "c:\keys\root.ppk"
objScp.CopyToRemote "Smalltoken.file", "."

Recursive property

Type:

Boolean

Description:

Specifies whether to recursively copy directories. To copy a directory and its subdirectories the recursive property should be enabled.

Example:

Set objScp           = CreateObject("ActiveXperts.Scp")         ' Create an Scp instance
...
objScp.Recursive = true
objScp.CopyToRemote "Smalltoken.file", "."

Compression property

Type:

Boolean

Description:

Specifies whether to use compression when copying files to the remote location. This will enable faster file transfer rates at the cost of a higher load on the server/client side.

Example:

Set objScp           = CreateObject("ActiveXperts.Scp")         ' Create an Scp instance
...
objScp.Compression = true
objScp.CopyToRemote "Smalltoken.file", "."

AcceptHostKey property

Type:

Boolean

Description:

Specifies whether to accept an unknown or changed host key and add it to the registry. Leaving this property set to true when connecting to unknown or untrusted hosts poses a security risk.

Example:

Set objScp           = CreateObject("ActiveXperts.Scp")         ' Create an Scp instance
...
objScp.AcceptHostKey = true
objScp.CopyToRemote "Smalltoken.file", "."

HostFingerprint property

Type:

String

Description:

The Scp 'CopyToRemote' and 'CopyToLocal' functions copy the host key fingerprint to this property

Example:

Set objScp           = CreateObject("ActiveXperts.Scp")         ' Create an Scp instance
...
objScp.CopyToRemote "Smalltoken.file", "."
WScript.Echo "Host key fingerprint: " & objScp.HostFingerprint

LogFile property

Type:

String

Description:

For troubleshooting purposes, you can specify a log file to trace all operations. By default, the 'LogFile' property holds the empty string. By assigning a valid filename to it, all operations will be written to this log file.

Example:

Set objScp           = CreateObject("ActiveXperts.Scp")         ' Create an Scp instance
...
objScp.LogFile = "Log.txt"
objScp.CopyToRemote "Smalltoken.file", "."

17.3. Functions

Functions

Function Description
Clear Reset all properties to the default values
CopyToLocal Copy the files to the local host
CopyToRemote Copy the files to the remote host
GetErrorDescription Get the description of the given error
Sleep Suspends the execution of the object for at least the specified interval
Activate Activate Software

Clear function

Description:

Reset all properties to the initial values.

Parameters:

  • None

Return value:

Always 0.

Example:

Set objScp = CreateObject("ActiveXperts.Scp")                   ' Create an Scp instance
...
objScp.CopyToRemote "Smalltoken.file", "."
objScp.Clear                                                    ' Resets properties
' Set new property values
...
objScp.CopyToRemote "Smalltoken.file", "."
objScp.Clear
...

CopyToLocal function

Description:

Copy a file or directory from the remote host specified in the 'Host' property to the local host.

Parameters:

  • The remote source path
  • The local destination path

Return value:

Always 0.

Example:

Set objScp = CreateObject("ActiveXperts.Scp")                   ' Create an Scp instance
...
objScp.CopyToLocal "Smalltoken.file", "C:\test"

CopyToRemote function

Description:

Copy a file or directory from the local to the remote host specified in the 'Host' property.

Parameters:

  • The local source path
  • The remote destination path

Return value:

Always 0.

Example:

Set objScp = CreateObject("ActiveXperts.Scp")                   ' Create an Scp instance
...
objScp.CopyToRemote "Smalltoken.file", "/var/www/upload"

GetErrorDescription function

Description:

GetErrorDescription provides the error description of a given error code.

Parameters:

  • Error code

Return value:

The error description that is associated with the given error code.

Example:

Set objScp           = CreateObject("ActiveXperts.Scp")         ' Create an Scp instance
objScp.Host          = "192.168.1.10"
objScp.UserName      = "mjohnson"
objScp.Password      = "topsecret"
objScp.CopyToRemote "Smalltoken.file", "."
WScript.Echo "Error description: " & objScp.GetErrorDescription( objScp.LastError )

Sleep function

Description:

This function can be used in your script anywhere you want. Suspends the execution of the object for at least the specified interval.

  • The number of milliseconds to suspend

Return value:

Always 0.

Example:

Set objScp         = CreateObject( "ActiveXperts.Scp" )         ' Create Scp object
...
objScp.Sleep 500

Activate function

Description:

This function activates the ActiveSocket product. A valid registration code is required.

Parameters:

  • The registration key
  • Persistent - this optional Boolean variable (default: True) specifies whether you want to add the registration key to the registry.
    If you pass 'True', you need to call the 'Activate' function only once for that computer.
    If you pass 'False', you need to call 'Activate' each time you create the object on that computer. This can be useful for customers who own a Distribution License of the product but do not want to show the registration key to their customers (see also here)

Return value:

Always 0. Check LastError property to see if the function was completed successfully.

Example:

Set objScp         = CreateObject( "ActiveXperts.Scp" )         ' Create Scp object
objScp.Activate "xyz", True     ' Substitute xyz by your own registrationkey
' Pass True to make the activation persistent, so you need to call
' Activate only once. If you pass False, you need to call
' Activate each time the product is started

18. SFtp

18.1. Introduction

SFTP (Secure File Transfer Protocol) allows secure network file transfer over an insecure network, such as the Internet.

The Secure File Transfer Protocol is an extension to the SSH version 2.0 protocol. Most SSH server implementations will also allow for SFTP logins. SFTP is the secure successor to SFTP.

The ActiveSocket SFTP implementation is based on the PuTTY implementation. With the ActiveSocket SFtp object, you can login onto a remote machine running the SSH-2 daemon and has the SFTP service enabled.

There are two ways to authenticate: by using a password or by using a 'private key'. When using a password to authenticate it is required that the host private key is known to the system. If the hosts private key is unknown to the system or if it was changed since the last connection the Sftp object will return an error. To connect anyway and store the host key in the registry for future connections the 'AcceptHostKey' property can be set.

NOTE:

  • The ActiveSocket SFtp object is not thread safe (A process can only have one active session). However, it is possible to run multiple processes with active sessions at once.

The following sample (in VBScript) changes to a 'test' directory, lists the directory and gets the 'Smalltoken.file' file on '192.168.1.10' by logging in using a password:

  ' 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."

18.2. Properties

Properties

Property Type Read/Write Description
Name String Out Filename
IsDirectory Boolean Out Is the file a directory (True) or a file (False)
SizeBytes Number Out Size of file (in bytes)
SizeBytesHigh Number Out High part of he size of the file
SizeKB Number Out Size of file (in kilobytes)
SizeMB Number Out Size of file (in megabytes)
DateSeconds Number Out Last modification date of the file (in seconds after 1/1/1970)
Date String Out Last modification date of the file (as a friendly string)
Version String Out Version number of ActiveSocket
Build String Out Display build information of ActiveSocket
ExpirationDate String Out Expiration date of ActiveSocket
LastError Number Out Result of the last called function
ProtocolError String Out If the last called function triggered a protocol error. This property will contain more information.
Host String In/Out Specifies the host to connect to
Port Number In/Out TCP port number to identify a (remote) SFTP daemon. Default: 22
UserName String In/Out Specifies the user name to use on the remote host
Password String In/Out Specifies the password to use on the remote host. If this property is left blank the 'PrivateKeyFile' property will be used to authenticate.
PrivateKeyFile String In/Out Specifies the private key file to logon to the remote host. If this property is left blank the 'password' property will be used to authenticate.
AcceptHostKey Boolean In/Out Specifies whether to accept an unknown or changed host key
HostFingerprint String Out The SFtp 'Connect' function copies the host key fingerprint to this property
Compression Boolean In/Out Specifies whether compression should be used while transferring files
LogFile String In/Out Log file; use it for troubleshooting purposes

Name property

Type:

String

Description:

File name.

Example:

Set objSFtp = CreateObject( "ActiveXperts.SFtp" )               ' Create a new SFtp instance
...
objSFtp.Connect                                                 ' Connect to the SFTP server    
...
Set objSFtpFile = objSFtp.FindFirstFile(".")                    ' Get first file in the
                                                                ' directory
If( objSFtp.LastError = 0 ) Then                           
   WScript.Echo "Name   : " & objSFtpFile.Name                  
   WScript.Echo "IsDirectory  : " & objSFtpFile.IsDirectory      
   WScript.Echo "Size (in bytes) : " & objSFtpFile.SizeBytes   
   WScript.Echo "DateSeconds : " & objSFtpFile.DateSeconds     
   WScript.Echo "Date : " & objSFtpFile.Date                    ' Display last modified 
                                                                ' date/time as a friendly string
End If
...
objSFtp.Disconnect                                              ' Disconnect

IsDirectory property

Type:

Boolean

Description:

True indicates a directory, False indicates a file.

Example:

Set objSFtp = CreateObject( "ActiveXperts.SFtp" )               ' Create a new SFtp instance
...
objSFtp.Connect                                                 ' Connect to the SFTP server    
...
Set objSFtpFile = objSFtp.FindFirstFile(".")                    ' Get first file in the 
                                                                ' directory
If( objSFtp.LastError = 0 ) Then                           
   WScript.Echo "Name   : " & objSFtpFile.Name                  
   WScript.Echo "IsDirectory  : " & objSFtpFile.IsDirectory      
   WScript.Echo "Size (in bytes) : " & objSFtpFile.SizeBytes   
   WScript.Echo "DateSeconds : " & objSFtpFile.DateSeconds     
   WScript.Echo "Date : " & objSFtpFile.Date                    ' Display last modified 
                                                                ' date/time as a friendly string
End If
...
objSFtp.Disconnect                                              ' Disconnect

SizeBytes property

Type:

Number

Description:

Size (in bytes) of the file. This field is actually the lower part of a 64Bit file size. The high part is located in the SizeBytesHigh property. Using only this property will be sufficient if files are not bigger than 4GB.

Example:

Set objSFtp = CreateObject( "ActiveXperts.SFtp" )               ' Create a new SFtp instance
...
objSFtp.Connect                                                 ' Connect to the SFTP server    
...
Set objSFtpFile = objSFtp.FindFirstFile(".")                    ' Get first file in the 
                                                                ' directory
If( objSFtp.LastError = 0 ) Then                           
   WScript.Echo "Name   : " & objSFtpFile.Name                  
   WScript.Echo "IsDirectory  : " & objSFtpFile.IsDirectory       
   ' Calculate the size of the file.
   WScript.Echo "Size (in bytes) : " & _ 
     (objSFtpFile.SizeBytesHigh * (2^32) + bjFtpFile.SizeBytes)
   WScript.Echo "DateSeconds : " & objSFtpFile.DateSeconds     
   WScript.Echo "Date : " & objSFtpFile.Date                    ' Display last modified 
                                                                ' date/time as a friendly string
End If
...
objSFtp.Disconnect                                              ' Disconnect

SizeBytesHigh property

Type:

Number

Description:

The high 32bit part of he size of the file. The lower part is located in the SizeBytes property. If the filesize is smaller than 4GB this property will be 0.

Example:

Set objSFtp = CreateObject( "ActiveXperts.SFtp" )               ' Create a new SFtp instance
...
objSFtp.Connect                                                 ' Connect to the SFTP server    
...
Set objSFtpFile = objSFtp.FindFirstFile(".")                    ' Get first file in the 
                                                                ' directory
If( objSFtp.LastError = 0 ) Then                           
   WScript.Echo "Name   : " & objSFtpFile.Name                  
   WScript.Echo "IsDirectory  : " & objSFtpFile.IsDirectory      
   ' Calculate the size of the file.
   WScript.Echo "Size (in bytes) : " & _
     (objSFtpFile.SizeBytesHigh * (2^32) + bjFtpFile.SizeBytes)
   WScript.Echo "DateSeconds : " & objSFtpFile.DateSeconds     
   WScript.Echo "Date : " & objSFtpFile.Date                    ' Display last modified 
                                                                ' date/time as a friendly string
End If
...
objSFtp.Disconnect                                              ' Disconnect

SizeKB property

Type:

Number

Description:

Contains the size in KB of the file when the file size is smaller than 4TB (4 Terabyte; 4 * 2^40 Bytes).

Example:

Set objSFtp = CreateObject( "ActiveXperts.SFtp" )               ' Create a new SFtp instance
...
objSFtp.Connect                                                 ' Connect to the SFTP server    
...
Set objSFtpFile = objSFtp.FindFirstFile(".")                    ' Get first file in the 
                                                                ' directory
If( objSFtp.LastError = 0 ) Then                           
   WScript.Echo "Name   : " & objSFtpFile.Name                  
   WScript.Echo "IsDirectory  : " & objSFtpFile.IsDirectory      
   WScript.Echo "Size (in KB) : " & objSFtpFile.SizeKB   
   WScript.Echo "DateSeconds : " & objSFtpFile.DateSeconds     
   WScript.Echo "Date : " & objSFtpFile.Date                    ' Display last modified 
                                                                ' date/time as a friendly string
End If
...
objSFtp.Disconnect                                              ' Disconnect

SizeMB property

Type:

Number

Description:

Contains the size in MB of the file when the file size is smaller than 4PB (4 Petabyte; 4 * 2^50 Bytes).

Example:

Set objSFtp = CreateObject( "ActiveXperts.SFtp" )               ' Create a new SFtp instance
...
objSFtp.Connect                                                 ' Connect to the SFTP server    
...
Set objSFtpFile = objSFtp.FindFirstFile(".")                    ' Get first file in the 
                                                                ' directory
If( objSFtp.LastError = 0 ) Then                           
   WScript.Echo "Name   : " & objSFtpFile.Name                  
   WScript.Echo "IsDirectory  : " & objSFtpFile.IsDirectory      
   WScript.Echo "Size (in MB) : " & objSFtpFile.SizeMB  
   WScript.Echo "DateSeconds : " & objSFtpFile.DateSeconds     
   WScript.Echo "Date : " & objSFtpFile.Date                    ' Display last modified 
                                                                ' date/time as a friendly string
End If
...
objSFtp.Disconnect                                              ' Disconnect

DateSeconds property

Type:

Number

Description:

last modified date and time of the file, in seconds after 1/1/1970.

Example:

Set objSFtp = CreateObject( "ActiveXperts.SFtp" )               ' Create a new SFtp instance
...
objSFtp.Connect                                                 ' Connect to the SFTP server    
...
Set objSFtpFile = objSFtp.FindFirstFile(".")                    ' Get first file in the 
                                                                ' directory
If( objSFtp.LastError = 0 ) Then                           
   WScript.Echo "Name   : " & objSFtpFile.Name                  
   WScript.Echo "IsDirectory  : " & objSFtpFile.IsDirectory      
   WScript.Echo "Size (in bytes) : " & objSFtpFile.SizeBytes   
   WScript.Echo "DateSeconds : " & objSFtpFile.DateSeconds     
   WScript.Echo "Date : " & objSFtpFile.Date                    ' Display last modified 
                                                                ' date/time as a friendly string
End If
...
objSFtp.Disconnect                                              ' Disconnect

Date property

Type:

String

Description:

last modified date and time of the file, as a friendly string.

Example:

Set objSFtp = CreateObject( "ActiveXperts.SFtp" )               ' Create a new SFtp instance
...
objSFtp.Connect                                                 ' Connect to the SFTP server    
...
Set objSFtpFile = objSFtp.FindFirstFile(".")                    ' Get first file in the 
                                                                ' directory
If( objSFtp.LastError = 0 ) Then                           
   WScript.Echo "Name   : " & objSFtpFile.Name                  
   WScript.Echo "IsDirectory  : " & objSFtpFile.IsDirectory      
   WScript.Echo "Size (in bytes) : " & objSFtpFile.SizeBytes   
   WScript.Echo "DateSeconds : " & objSFtpFile.DateSeconds     
   WScript.Echo "Date : " & objSFtpFile.Date                    ' Display last modified 
                                                                ' date/time as a friendly string
End If
...
objSFtp.Disconnect                                              ' Disconnect

Version property

Type:

String

Description:

Version information of ActiveSocket. This property is read-only; you cannot assign a value to it.

Example:

Set objSFtp = CreateObject( "ActiveXperts.SFtp" )            ' Create SFtp object
WScript.Echo  "Version: " & objSFtp.Version

Build property

Type:

String

Description:

Build information of ActiveSocket. This property is read-only; you cannot assign a value to it.

Example:

Set objSFtp = CreateObject( "ActiveXperts.SFtp" )           ' Create SFtp object
WScript.Echo  "Build: " & objSFtp.Build

ExpirationDate property

Type:

String

Description:

Expiration date of ActiveSocket. This property is read-only; you cannot assign a value to it.
Once you have registered the product, the property holds the empty string ("") value.

Example:

Set objSFtp = CreateObject( "ActiveXperts.SFtp" )            ' Create SFtp object
WScript.Echo "ExpirationDate: " & objSFtp.ExpirationDate

LastError property

Type:

Number

Description:

The result of a previous called function. Use it to check the result of your last function call. A zero indicates: success. Any non-zero value means an error.
The GetErrorDescription function provides the error description of an error code.
For a complete list of error codes, check out the following page: www.activexperts.com/support/errorcodes.

Example:

Set objSFtp           = CreateObject("ActiveXperts.SFtp")    ' Create an SFtp instance
...
objSFtp.Connect
WScript.Echo "LastError: " & objSFtp.LastError

ProtocolError property

Type:

String

Description:

If the last called function triggered a protocol error. This property will contain more information. The protocol error string is usually triggered and formulated into an error description at the remote host.

Example:

Set objSFtp           = CreateObject("ActiveXperts.SFtp")    ' Create an SFtp instance
...
objSFtp.Connect
WScript.Echo "ProtocolError: " & objSFtp.ProtocolError

Host property

Type:

String

Description:

Specifies the host on which to run the command.

Example:

Set objSFtp           = CreateObject("ActiveXperts.SFtp")    ' Create an SFtp instance
objSFtp.Host          = "server01.domain.dom"
...
objSFtp.Connect

Port property

Type:

Number

Description:

TCP port number to identify a remote SSH daemon. If you don't specify the 'Port' property, port 22 (default SSH port) is used.

Example:

Set objSFtp           = CreateObject("ActiveXperts.SFtp")    ' Create an SFtp instance
objSFtp.Host          = "server01.domain.dom"
objSFtp.Port          = 8022                                 ' Use port 8022 instead of 22
...
objSFtp.Connect

UserName property

Type:

String

Description:

Specifies the user name to use on the remote host. You must also specify either a Password or Private Key to logon to the machine.

Example:

Set objSFtp           = CreateObject("ActiveXperts.SFtp")    ' Create an SFtp instance
objSFtp.Host          = "server01.domain.dom"
objSFtp.UserName      = "mjohnson"
objSFtp.Password      = "topsecret"
objSFtp.Connect

Password property

Type:

String

Description:

Specifies the password to use on the remote host. If you do not use a password, you must use a Private Key to logon to the machine.

Example:

Set objSFtp           = CreateObject("ActiveXperts.SFtp")    ' Create an SFtp instance
objSFtp.Host          = "server01.domain.dom"
objSFtp.UserName      = "mjohnson"
objSFtp.Password      = "topsecret"
objSFtp.Connect

PrivateKeyFile property

Type:

String

Description:

Specifies the private key file to use on the remote host. If you do not use a private key, you must use a Password to logon to the machine.

Example:

Set objSFtp           = CreateObject("ActiveXperts.SFtp")    ' Create an SFtp instance
objSFtp.Host          = "server01.domain.dom"
objSFtp.UserName      = "mjohnson"
objSFtp.PrivateKeyFile= "c:\keys\root.ppk"
objSFtp.Connect

AcceptHostKey property

Type:

Boolean

Description:

Specifies whether to accept an unknown or changed host key and add it to the registry. Leaving this property set to true when connecting to unknown or untrusted hosts poses a security risk.

Example:

Set objSFtp           = CreateObject("ActiveXperts.SFtp")    ' Create an SFtp instance
...
objSFtp.AcceptHostKey = true
objSFtp.Connect

HostFingerprint property

Type:

String

Description:

The SFtp 'Connect' function copies the host key fingerprint to this property

Example:

Set objSFtp           = CreateObject("ActiveXperts.SFtp")    ' Create an SFtp instance
...
objSFtp.Connect
WScript.Echo "Host key fingerprint: " & objSFtp.HostFingerprint

Compression property

Type:

Boolean

Description:

Specifies whether to use compression when copying files to the remote location. This will enable faster file transfer rates at the cost of a higher load on the server/client side.

Example:

Set objSFtp           = CreateObject("ActiveXperts.SFtp")    ' Create an SFtp instance
...
objSFtp.Compression = true
objSFtp.Connect

LogFile property

Type:

String

Description:

For troubleshooting purposes, you can specify a log file to trace all operations. By default, the 'LogFile' property holds the empty string. By assigning a valid filename to it, all operations will be written to this log file.

Example:

Set objSFtp = CreateObject("ActiveXperts.SFtp")    ' Create an SFtp instance
...
objSFtp.LogFile = "Log.txt"
objSFtp.Connect

18.3. Functions

Functions

Function Description
Clear Reset all properties to their default values
Connect Connect to a remote SFTP server
Disconnect Close the connection