<< back to sysax.com Product page

1.1. Example script

The following example script demonstrates the invocation of the COM object from within VBScript. The script also shows how to connect to a remote host computer and perform upload, download and folder listing operations.

Exhibit 1.1. Invocation of the COM object from within VBScript


Option Explicit

'invoke the sysaxautomation component
Dim app
Set app = CreateObject("SysaxAutomation.Application")

'enable writing to log file
app.SetLogFile "c:\\mylog.txt", false, 0

'also enable output to console
app.ConsoleLog = true



'connect to a remote site
app.Host = "localhost" 'hostname or IP address of remote site
app.User = "test"      'account username
app.Pass = "test"      'password for account

app.FTPConnect         'connect to the site (default port is 21 for FTP)
                       'use "app.FTPConnect 21" to use explicit port
                       'use FTPConnectSSH for SFTP (default port is 22)
                       'use FTPConnectSSL for explicit FTPS (port 21)
                       'use FTPConnectSSLI for implicit FTPS (port 990)

'check if the connection was successful - continue only if successful
If app.IsFTPSuccess Then

  'set the local and remote paths
  app.FTPSetPath "local", "c:\\tmp"
  app.FTPSetPath "remote", "/"


  'upload a file to the remote site
  app.FTPUpload "file", "test.txt", ""
  If Not app.IsFTPSuccess Then
    WScript.Echo "failed to upload file"
  End If


  'download a file from the remote site
  app.FTPDownload "file", "test.txt", ""
  If Not app.IsFTPSuccess Then
    WScript.Echo "failed to download file"
  End If


  'list the contents of the remote folder - top level (non-recursive)
  Dim ftplist
  Set ftplist = app.FTPGetList("remote", 1)
  If Not app.IsFTPSuccess Then
    WScript.Echo "failed to list contents of remote folder"
  End If

  WScript.Echo "number of items in listing:", ftplist.Count

  Dim ftpitem
  For Each ftpitem In ftplist
    If ftpitem.IsFolder Then
      WScript.Echo "[folder]", ftpitem.Name, "(Size:", ftpitem.Size, "and Modification Timestamp:", ftpitem.ModTime, ")"
    Else
      WScript.Echo "[file]  ", ftpitem.Name, "(Size:", ftpitem.Size, "and Modification Timestamp:", ftpitem.ModTime, ")"
    End If
  Next


  'disconnect from the remote site
  app.FTPDisconnect

Else
  WScript.Echo "Could not connect to remote site"
End If