Telnet Object : Rsh Method |
Visual Basic |
---|
Public Sub Rsh( _ ByVal RemoteName As String, _ ByVal User As String, _ ByVal Command As String, _ Optional ByVal RemotePort As Long = 0, _ Optional ByVal LocalName As String, _ Optional ByVal LocalPort As Long = 0 _ ) |
This method requires authorization for the local host running your application. This is done by adding the proper entries to the hosts.equiv or .rhosts files located on the remote host. These files enable logins to be performed from other machines and users. The hosts.equiv file is a system file containing names of remote hosts authorized to execute the remote protocol. If not authorized in this file, the remote host looks for the .rhosts file located in the user's account on the remote host. The .rhosts file contains lines of host names and login names paired together. Your local host with login name is authorized if found in this file.
When invoked, a connection is initiated with the remote host using the remote shell protocol. The State property immediately changes to tcpConnecting and then changes to tcpConnected when the connection is established. The State Property can be checked in the body of the State event, polled off a timer, or checked immediately after the method is invoked when a positive Timeout is specified. Once connected, Command is sent where it executes on the remote host. Use the Receive method or Search method to capture output generated from the command. Upon command completion, the remote host closes the connection and the State event fires with the State property set to tcpClosed. This method is invoked as blocking or non-blocking, depending on the value of the Timeout property.
When performing blocked method calls, the Blocked property may be checked to verify the control is not busy executing another method.
Error Codes
The Rsh method may generate the following error codes (refer to the ErrorConstants topic for a complete list of error codes):
Private Sub Command1_Click() On Error GoTo OnError ' use intrinsic error handling Telnet1.Timeout = 1000 Telnet1.Rsh "myhost", "myUsername", "reboot" 'reboot remote UNIX host ' didn't go to OnError, so we connected and execute listing before 30 seconds elapsed! Exit Sub OnError: ' Any error jumps here ' no connection within 30 seconds, or other error (Tcp1.State is tcpClosed) Debug.Print "Error #" + CStr(Err.Number) + ": " + Err.Description End Sub
Private Sub Command1_Click() Telnet1.Timeout = 0 'connect and start executing listing followed by the date command 'this demonstrates executing multiple commands Telnet1.Rsh "myhost", "myUsername", "ls la; date" End Sub Private Sub Telnet1_State() If Telnet1.State = tcpConnected Then MsgBox "Connected!" End Sub Private Sub Telnet1_Receive() Dim Output As String Telnet1.Receive Output Text1.Text = Output End Sub