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)


VBScript 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 VBScript 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 the ActiveSocket Toolkit

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



Step 2: Create a new script

Create a new script using your favorite editor. You can simply use notepad. However, a VBScript editor is recommended, so you can browse through objects, objects properties and object functions.

You're now able to write a more advanced script to communicate using the ActiveSocket Toolkit.



Step 3: Create the ActiveSocket object in VBScript

Create a new VBScript file called DEMO.VBS. It is recommended to insert the following line on top of your code:
   Option Explicit
This statement requires that all variable names be defined (with the Dim statement), to avoid simple typos that can cause incredible headaches and long debugging sessions for something that should have never happened.

Now, declare the ActiveSocket object(s):
   Dim objFtpServer
Create the ActiveSocket object(s) like this:
   Set objFtpServer      = CreateObject( "ActiveXperts.FtpServer" )
Now, add the following lines to the file to have your fist ActiveSocket VBScript program:
   WScript.Echo "Version: " & objFtpServer.Version
   WScript.Echo "Expiration Date: " & objFtpServer.Expiration Date


Step 4: Connect to a remote FTP server, change directory and list all files

You can now connect to a remote FTP server, logon, change directory and perform file operations.
The following VBScript code shows how to list files in a specific directory on a remote FTP server:
Option Explicit

Dim objConstants, objFtpServer, objFtpFile, strSaveAs

Set objFtpServer = CreateObject ( "ActiveXperts.FtpServer" )

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

' Log all FTP operations
objFtpServer.LogFile = "C:\ftpget.txt"

' Connect to the remote FTP server
objFtpServer.Connect "ftp.activexperts-labs.com", "anonymous", "me@myself.dom" 
Wscript.Echo "Connect, result: " & objFtpServer.LastError & " (" & objFtpServer.GetErrorDescription ( objFtpServer.LastError ) & ")"
If( objFtpServer.LastError <> 0 ) Then
   Wscript.Echo "Ready."
   WScript.Quit
End If

' Show last response of FTP server
WScript.Echo "Last response: " & objFtpServer.LastResponse

' Use binary transfer for GetFile calls
objFtpServer.BinaryTransfer = True

' Change directory
objFtpServer.ChangeDir "/Samples/ASocket/Visual Basic/Demo" 
Wscript.Echo "ChangeDir, result: " & objFtpServer.LastError & " (" & objFtpServer.GetErrorDescription ( objFtpServer.LastError ) & ")"
If( objFtpServer.LastError <> 0 ) Then
   objFtpServer.Disconnect
   Wscript.Echo "Disconnected."
   Wscript.Echo "Ready."
   WScript.Quit
End If

' Iterate over all files
Set objFtpFile = objFtpServer.FindFirstFile()
Wscript.Echo "Find file, result: " & objFtpServer.LastError & " (" & objFtpServer.GetErrorDescription ( objFtpServer.LastError ) & ")"
' WScript.Echo "Last response: " & objFtpServer.LastResponse
While ( objFtpServer.LastError = 0 )

   WScript.Echo "Name: " & objFtpFile.Name 
   WScript.Echo "   IsDirectory: " & objFtpFile.IsDirectory
   WScript.Echo "   Size (bytes): " & objFtpFile.Size
   WScript.Echo "   Creation date (seconds): " & objFtpFile.DateSeconds
   WScript.Echo "   Creation date: " & objFtpFile.Date
    
   ' To save the file, call the GetFile function. 
   ' strSaveAs = "C:\temp\" & objFtpFile.Name
   ' objFtpServer.GetFile objFtpFile.Name, strSaveAs 
   ' Wscript.Echo "Save file as " & strSaveAs & ", result: " & objFtpServer.LastError & " (" & objFtpServer.GetErrorDescription ( objFtpServer.LastError ) & ")"

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

   Set objFtpFile = objFtpServer.FindNextFile()
   Wscript.Echo "Find file, result: " & objFtpServer.LastError & " (" & objFtpServer.GetErrorDescription ( objFtpServer.LastError ) & ")"
Wend

objFtpServer.Disconnect
Wscript.Echo "Disconnected."
Wscript.Echo "Ready."
There are many working samples included with the product. You can also find them on the ActiveXperts FTP site: ftp.activexperts-labs.com/samples/asocket.





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.