Quicklinks
NOTE: ActiveXperts Network Monitor ships with a large collection of PowerShell scripts to monitor any aspect of your network. Most PowerShell scripts also have a VBScript implementation. Download Now »
You can use any of the Powershell programs below in ActiveXperts Network Monitor. Click here for an explanation about how to include scripts in ActiveXperts Network Monitor.
################################################################################# # ActiveXperts Network Monitor PowerShell script, © ActiveXperts Software B.V. # For more information about ActiveXperts Network Monitor, visit the ActiveXperts # Network Monitor web site at http://www.activexperts.com ################################################################################# # Script # FTP.ps1 # Description: # Login to an FTP server, change the directory and check for file existence. # This function uses the ActiveSocket Toolkit, an ActiveXperts product. # ActiveSocket is automatically licensed when ActiveXperts Network Monitor is purchased # For more information about ActiveSocket, see: www.activexperts.com/network-component # Parameters: # 1) strHost - Host name or IP address of the FTP host # 2) strAccount - FTP account; use #anonymous# for anonymous FTP access # 3) strPassword - FTP password; use an e-mail address for anonymous FTP access # 4) strDir - The directory where the file should be located # 4) strFile - The file to check # Usage: # .\FTP/ps1 "" " " " " " " " " # Sample: # .\FTP.ps1 "ftp.activexperts-labs.com" "anonymous" "me@myself.me" "Samples/NetworkMonitor" "NetworkMonitor.txt" ################################################################################# # Parameters param ( [string]$strHost, [string]$strAccount, [string]$strPassword, [string]$strDir, [string]$strFile ) cls # Check paramters input if( ([string]$strHost -eq "") -or ([string]$strAccount -eq "") -or ([string]$strPassword -eq "") -or ([string]$strDir -eq "") -or ([string]$strFile -eq "") ) { $res = "UNCERTAIN: Invalid number of parameters - Usage: .\ftp.ps1 " echo $res exit } $found = $false # Create object $objFtpServer = new-object -comobject ActiveXperts.FtpServer $objFtpServer.Connect( $strHost, $strAccount, $strPassword ) if( $objFtpServer.LastError -ne 0 ) { return "UNCERTAIN: Login failed, error #" + $objFtpServer.LastError + ": " + $objFtpServer.GetErrorDescription( $objFtpServer.LastError ) exit } ################################################################################# # THE SCRIPT ITSELF ################################################################################# # Use binary transfer for GetFile calls $objFtpServer.BinaryTransfer = $true # Change directory $objFtpServer.ChangeDir($strDir) if( $objFtpServer.LastError -ne 0 ) { return "UNCERTAIN: Failed to change directory, error #" + $objFtpServer.LastError + ": " + $objFtpServer.GetErrorDescription( $objFtpServer.LastError ) exit } # Iterate over all files $objFtpFile = $objFtpServer.FindFirstFile() while ( $objFtpServer.LastError -eq 0 ) { if( $objFtpFile.Name -eq $strFile ) { $found = $true $objFtpServer.Disconnect() } $objFtpFile = $objFtpServer.FindNextFile() } if ( $found -eq $true ) { return "SUCCESS: File [" + $strFile + "] found on FTP server [" + $strHost + "]" } else { return "ERROR: File [" + $strFile + "] not found on FTP server [" + $strHost + "]" } $objFtpServer.Disconnect()