Telnet and Remote Login  
 

To establish a terminal session with a server, you can either use the Telnet control or the Remote Command control. Telnet is a standard protocol which is used to provide basic terminal services, and is more widely supported than the Remote Login (rlogin) protocol. The following example demonstrates connecting to a Telnet server, listing the files in the user's current directory and capturing the output:

Dim strCommand As String
Dim strOutput As String
Dim strBuffer As String
Dim nResult As Long
Dim nError As Long

' Establish a connection with the server
nError = TelnetClient1.Connect(strHostName)
If nError Then
    MsgBox TelnetClient1.LastErrorString, vbExclamation
    Exit Sub
End If

' Login to the server as the specified user
nError = TelnetClient1.Login(strUserName, strPassword)
If nError Then
    MsgBox TelnetClient1.LastErrorString, vbExclamation
    TelnetClient1.Disconnect
    Exit Sub
End If

' Issue a UNIX command to list the contents of the user's
' home directory and then logout
strCommand = "/bin/ls -l; exit" & vbCrLf
TelnetClient1.Write strCommand, Len(strCommand)

' Read the data returned by the server and collect it
' in the strOutput string
Do
    nResult = TelnetClient1.Read(strBuffer, 4096)
    If nResult > 1 Then strOutput = strOutput + strBuffer
Loop Until nResult < 1

' Disconnect from the server
TelnetClient1.Disconnect

After the connection has been established, the Login method is used to automatically login the user. It is important to note that this method expects that the server will respond with the standard Username: and Password: prompts that most UNIX and Windows based Telnet servers use. If the server uses a non-standard login sequence, then the client will need to use the Search method to search for the prompts and write code to respond to them. Note that many servers are configured to not permit the administrator (root) account to login using Telnet. If you are unable to login, check with your system administrator to determine if you have sufficient privileges to establish a telnet session from your local system.

An example using the Remote Command control to login to a server is very similar, however there are a few important differences:

Dim strCommand As String
Dim strOutput As String
Dim strBuffer As String
Dim nResult As Long
Dim nError As Long

' Login to the server as the specified user
nError = RshClient1.Login(strHostName, , strUserName)
If nError Then
    MsgBox RshClient1.LastErrorString, vbExclamation
    RshClient1.Disconnect
    Exit Sub
End If

' Issue a UNIX command to list the contents of the user's
' home directory and then logout
strCommand = "/bin/ls -l; exit" & vbCrLf
RshClient1.Write strCommand, Len(strCommand)

' Read the data returned by the server and collect it
' in the strOutput string
Do
    nResult = RshClient1.Read(strBuffer, 4096)
    If nResult > 1 Then strOutput = strOutput + strBuffer
Loop Until nResult < 1

' Disconnect from the server
RshClient1.Disconnect

Instead of a Connect method, the control uses the Login method to establish the connection and login the user. It is also important to note that a username is provided, but there is no password. This is because the rlogin protocol uses a concept called host equivalence. This means that the server must be specifically configured to allow the user to login from your local system. If the system administrator has not done this, then attempts to connect to the server will fail with the error that the connection has been aborted. If you need to use the rlogin protocol, most likely you will need to contact your system administrator to make the appropriate changes to permit access to the server.