Remote Command Execution | ||
To execute a command on a server, you can Remote Command control. The following example demonstrates connecting to a UNIX server, listing the files in the user's current directory and capturing the output: Dim strCommand As String Dim strBuffer As String Dim strOutput As String Dim nResult As Long, nError As Long ' Execute the command on the server nError = RshClient1.Execute(strHostName, rshPortExec, strUserName, strPassword, strCommand) If nError > 0 Then MsgBox RshClient1.LastErrorString, vbExclamation Exit Sub End If ' Read the output from the command and store it in a ' string buffer Do nResult = RshClient1.Read(strBuffer, 1024) If nResult > 1 Then strOutput = strOutput + strBuffer Loop Until nResult < 1 ' Disconnect from the server RshClient1.Disconnect The Execute method establishes the connection to the server, authenticates the user and executes the command. The output from the command is read using the Read method. Note that this method should only be used if the command is not interactive and expect character-mode input. For example, the Execute method should not be used with editors such as Emacs. For interactive sessions or the ability to execute multiple commands in a single client session, the Telnet or Rlogin protocols should be used instead. |
||
Copyright © 2023 Catalyst Development Corporation. All rights reserved. |