ActiveSocket

 Product Overview

 ActiveSocket Objects:
 
 How to use

 Online Samples

 Download (.exe)

 Brochure (.pdf)

 Manual (.htm)

 Release Notes


Support

 Knowledge Base

 Forum

 Contact Support


Purchase

 Licensing

 Pricing

 Order now


Related documents

 Tutorials

 Tools


  Download ActiveSocket Network Communications Toolkit 4.1  (5094 KB - .exe file)
  Download Manual  (505 KB - .htm file)


ASP 2.x FTP Client Sample Source Code


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

ActiveSocket features the following: ICMP, HTTP and HTTPs with support for proxy servers and secure web sites, Telnet, NTP time protocol, RSH remote shell script interface, SNMP (Simple Network Management Protcol), SNMP Traps, Sockets, WOL (Wake-On-LAN), and more.

ActiveSocket can be well integrated into ASP environments.
This document describes how the ActiveSocket FtpServer object can be integrated into ASP projects.

The most important functions of the FtpServer object are:
  • Connect - connect to the (remote) FTP server on port 21 or any alternate port;
  • Disconnect - to diconnect after a connect call;
  • GetCurrentDir - retrieve the current directory;
  • ChangeDir - change the current directory;
  • CreateDir - create a new directory;
  • RenameDir - rename a directory;
  • DeleteDir - delete a directory;
  • FindFile - find a specific file in the current directory;
  • FindFirstFile - iterate over all files in the current directory; find the first file;
  • FindNextFile - iterate over all files in the current directory; find the next file;
  • RenameFile - rename a file in the current directory;
  • DeleteFile - delete a file in the current directory;
  • GetFile - get (download) a file, either using binary transfer or ASCII transfer;
  • PutFile - put (upload) a file, either using binary transfer or ASCII transfer;

Step 1: Download and install ActiveSocket

Download ActiveSocket 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':

    
    (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 ActiveSocket.



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 ActiveSocket 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: Making it happen

You can list files using ActiveSocket ftp in 3 steps.
  1. Creating an object to use ActiveSocket
  2. Connect to the server
  3. List the files
Creating the object
Now that we have all the information we need, we need to create an object witch supports communicating through ActiveSocket. To do this we only need one line of code:

   Set objFtp = Server.CreateObject( "ActiveXperts.FtpServer" )


Connecting to the server
To connect to the server we're using the ActiveSocket method "Connect".
 objFtp.connect request("server"), request("username"), request("password")

This makes a code look like this:
if request("submitbutton") <> "" then

  dim objFiles

  ' create the object
  Set objFtp = Server.CreateObject( "ActiveXperts.FtpServer" )
	
  objFtp.clear
	
  ' set the logfile
  objFtp.logfile = request("logfile")
  
  ' connect
  objFtp.connect request("server"), request("username"), request("password")
  objFtp.ChangeDir request("directory")
	
else
  ' do nothing
end if

Listing the files
If the previous actions have been succesfully executed, we can list the files. To list these files we're using two ActiveSocket methods:
  1. We're using "FindFirstFile" to find the first file.
  2. We're using "FindNextFile" to move on to the next.
When we know what the first file is we're starting a loop. If one file is listed, FindNextFile is used to move on to the next. If there is no more file, the software will return an error. Thats why we created the following code:

  ' find the first file
  if objFtp.LastError <> 0 then
    response.write("Connection failed..<br>")
  else
    set objFiles = objFtp.FindFirstFile()
  end if
	
  ' list the files
  if objFtp.LastError <> 0 then
    response.write("<tr><td>Sorry.. Failed to list the files..</td></tr>")
  else
    getfiles
  end if	


sub getfiles

  'show the contents in a table
  response.write ("Files in directory " & request("directory") & " :")	
  response.write ("<table>")
	
  'the software will return an error if there is no more file to display, so:
  do while objFtp.LastError = 0
     response.write("<tr>")
     response.write("<td>")
		 
     'display folders
     if objFiles.IsDirectory = 0 then
       response.write "File:"
     else
       response.write "Directory:"
     end if
	   
     response.write("</td>")
     response.write("<td class=files>")		 		 		 		 
	   
     'display the names
     response.write(objFiles.name)
		 
     response.write("</td>")
     response.write("</tr>")
		 
     'find the next file; continue the loop
     set objFiles = objFtp.FindNextFile 
  loop

  response.write "</table>"
	
end sub






The ActiveSocket tool is a Network Communications ActiveX software component (SDK). This control supports SNMP, SMTP, POP3, Telnet, TCP, NTP, RSH, HTTP, HTTPs, FTP, DNS, ICMP and more, and can be used by any Windows development platform, including Visual Basic .NET, Visual CSharp .NET, ASP .NET (VB,CS), ASP, Visual Basic, Visual Studio/Visual C++, Delphi, PHP, ColdFusion, HTML, VBScript and any other ActiveX/COM compliant platform. The ActiveSocket Toolkit is an ActiveXperts Software B.V. Product.

Copyright ©1999-2007 ActiveXperts Software. All rights reserved.