ActiveXperts Network Component

Quicklinks

SSH Sample Source Code in ASP

Network Component provides an easy-to-use development interface to a variety of IP protocols. By using Network Component, you can very easily create or enhance applications with network features.

Network Component features the following: DNS, FTP, HTTP, HTTPs, ICMP Ping, IP-to-Country, MSN, NTP, RSH, SCP, SFTP, SNMP v1/v2c (Get, GetNext, Set), SNMP Traps, SNMP MIB, SSH, TCP, Telnet, TFTP, UDP, Telnet, Wake-On-LAN and more.

Network Component can be well integrated into any development platform that supports ActiveX objects.



Step 1: Download and install Network Component

Download Network Component from the ActiveXperts Download Site and start the installation. The installation guides you through the installation process.

Step 2: Create a new Web Site

First, create a new directory on the IIS Server's file system. This directory will hold the ASP later on.

From the 'Start menu', click on 'Administrative Tools' and click on 'Internet Information Services (IIS) Manager'. Right-click on the 'Web Sites' container and choose 'New->Web Site':

IIS

(Click on the picture to enlarge)

The 'Web Site Creation Wizard' is shown, guiding you thorugh the process of creating a new web site. Provide all necessary information:

  • Description - a friendly description of the new site;
  • IP / Port / Host Header - choose your preferred way to distinguish between other web sites on the server;
  • Path - select the directory that will store the ASP file(s);
  • Web Site Access Permissions - in the Web Site Access Permissions dialog, enable 'Read' and 'Run scripts (such as ASP)';

You're now able to write an ASP script to use IP protocols with Network Component.

Step 3: Create the from

First of all we need to create a form in HTML to get the login information for the ftp server. All we actually need is:

  • The log-in name.
  • The password.
  • The server we want to connect to.
  • And the directory we're going to list.

In this sample all we're going to do is create a ASP file that is able to list files and directories in a directory. Using Network Component it is easy to create a page that makes you able to upload and to download files.

You can create a form that looks like this:

(Click on the picture to enlarge)

Step 4:Create ActiveXperts Network Component objects in ASP

Create a new ASP script called DEFAULT.ASP in the directory that was created in Step2, using your favorite editor. On top of the ASP code, insert the following lines to declare and create the Dns object:

<object runat="server" progid="AxNetwork.Ssh" id="objSftp"></object>
<object runat="server" progid="AxNetwork.ASConstants" id="objConstants"></object>

Appendix: Full source code

<object runat="server" progid="AxNetwork.Ssh" id="objSsh"> </object>

<%
' HTML-CSS layout includes below, no code there!
%>
<!-- #include file="css/Header.html" -->
<!-- #include file="css/Menu.html" -->

<%
  ' A license key is required to unlock this component after the trial period has expired.
  ' Call 'Activate' with a valid license key as its first parameter. Second parameter determines whether to save the license key permanently 
  ' to the registry (True, so you need to call Activate only once), or not to store the key permanently (False, so you need to call Activate
  ' every time the component is created). For details, see manual, chapter "Product Activation".
  '
  ' objSsh.Activate "XXXXX-XXXXX-XXXXX", False    
%>

<%
  Dim numLastError, strLastError, objDnsRecord, strResponse

  Set fso = CreateObject("Scripting.FileSystemObject")
  strLogfile = fso.GetSpecialFolder(2) & "\Ssh.log"
  
  strLastError             = ""
  strStdOut                = ""
  strStdErr                = ""

  If( Request( "btnSubmit" ) <> "" ) Then
    objSsh.Clear
    objSsh.Host           = Request( "txtRemoteHost" )
    objSsh.UserName       = Request( "txtUser" )
    objSsh.Password       = Request( "txtPassword" )
    objSsh.PrivateKeyFile = Request( "txtPrivateKeyFile" )
    objSsh.Command        = Request( "txtCommand" )
    objSsh.ScriptTimeOut  = Request( "txtTimeout" )
    objSsh.LogFile        = Request( "txtLogFile" )  ' Optional: set LogFile property for troubleshooting purposes
    objSsh.Run
    numLastError          =  objSsh.LastError

    strStdOut             = objSsh.StdOut
    strStdErr             = objSsh.StdErr

    strLastError = numLastError & ": " & objSsh.GetErrorDescription( numLastError )  
  End If
%>

<div class="ax_container">
  <h1>ActiveXperts Network Component ASP Sample - SSH</h1>

  <form action="ssh.asp" method="post">
    <h2>Component:</h2>
    <h3>Module [<% = objSsh.Module %>]; Build [<% = objSsh.Build %>]</h3>
    
    <!-- Remote Host: -->
    <label for="remotehost">Remote Host:</label>
    <p>
      <input type="text" name="txtRemoteHost" value="<% If Request( "txtRemoteHost" ) = "" Then %>srv202.activexperts-labs.com<% Else %><% = Request( "txtRemoteHost" ) %><% End If %>">
      Port: 
      <input style="width: 50px" type="text" name="CTL_PORT" value="<% If Request( "CTL_PORT" ) = "" Then %>22<% Else %><% = Request( "CTL_PORT" ) %><% End If %>">
    </p>
    
    <!-- User -->
    <label for="user">User:</label>
    <p>
      <input  type="text" name="txtUser" value="<% If Request( "txtUser" ) = "" Then %>activexperts<% Else %><% = Request( "txtUser" ) %><% End If %>">
    </p>
    
    <!-- Password -->
    <label for="Password">Password:</label>
    <p>
      <input type="password" name="txtPassword" value="<% If Request( "txtPassword" ) = "" Then %>topsecret<% Else %><% = Request( "txtPassword" ) %><% End If %>">
    </p>
    
    <!-- Private Key File -->
    <label for="Private Key File">Private Key File:</label>
    <p>
      <input type="text" name="txtPrivateKeyFile" value="<% If Request( "txtPrivateKeyFile" ) = "" Then %><% Else %><% = Request( "txtPrivateKeyFile" ) %><% End If %>">
    </p> 
    
    <!-- Run this command -->
    <label for="Run this command">Run this command:</label>
    <p>
      <input type="text" name="txtCommand" value="<% If Request( "txtCommand" ) = "" Then %>ls -als c:\sshroot\network-component<% Else %><% = Request( "txtCommand" ) %><% End If %>">
    </p> 
    
    <!-- Command Timeout -->
    <label for="Command Timeout">Command Timeout:</label>
    <p>
      <input style="width: 150px" type="text" name="txtTimeout" value="<% If Request( "txtTimeout" ) = "" Then %>10000<% Else %><% = Request( "txtTimeout" ) %><% End If %>">
    </p> 
    
    <!-- Run Command Button -->
    <div class="ax_clearLabel"></div>
    <p>
      <input size="25" type="submit" value="Run Command" name="btnSubmit" >
    </p>
    
    <!-- Emty Row -->
    <div class="ax_clearRow"></div> 

    <!-- Logfile -->
    <label for="Logfile">Logfile:</label>
    <p>
      <input type="text" id="LogFile" name="txtLogFile" class="ax_FullWidth" value="<% = strLogfile %>" />
    </p> 
    
    <!-- Result code -->
    <label for="Result">Result code:</label>
    <p>
        <input type="text" id="Result" name="txtResult" class="ax_FullWidth" style="font-weight: bold;" value="<% = strLastError %>" />
    </p>  
    
    <!-- StdOut -->
    <label for="stdout">StdOut:</label>
    <p>
      <textarea name="CTL_STDOUT" rows="10" cols="60" class="ax_FullWidth"><% = strStdOut %></textarea>
    </p>
    
     <!-- StdOut -->
    <label for="stdout">StdErr:</label>
    <p>
      <textarea name="CTL_STDOUT" rows="10" cols="60" class="ax_FullWidth"><% = strStdErr %></textarea>
    </p>
    
  </form>
  <p>
    This sample is based on ActiveXperts Network Component, an<a href="http://www.activexperts.com/" target="_blank">ActiveXperts Software</a> product.<br />
    <a href="Default.asp">Back to main page</a>
  </p>
</div><!-- /container -->
<%
' HTML-CSS layout include below, no code there!
%>
<!-- #include file="css/Footer.html" -->

You can download the complete sample on our FTP site ftp.activexperts-labs.com/samples/network-component/. There are many other working Network Component scripts on our site and shipped with the product.