Here is a code snippet for a tcpclient connection:
Sub Main()
Dim host As String = "192.168.1.50"
Dim TCPClient As New TcpClient
'Connect to telnet
TCPClient.Connect(host, 23)
'Get our networkstream
Dim netstream As NetworkStream = TCPClient.GetStream()
Dim buffer(1024) As Byte
'Get the ASCII encoder to convert the text back and forth on the stream (bytes <--> strings)
Dim encoding As New System.Text.ASCIIEncoding
Dim hasLoggedUser, hasLoggedPass As Boolean
Do While True
'Begin reading data into buffer (this statement is blocking)
netstream.Read(buffer, 0, buffer.Length)
'Clean up for displaying
Dim bufferedstring As String = encoding.GetString(buffer)
bufferedstring = Replace(bufferedstring, vbCr, "")
bufferedstring = Replace(bufferedstring, vbLf, "")
bufferedstring = Replace(bufferedstring, Chr(0).ToString(), "")
Console.WriteLine(" RECV: {0}", bufferedstring)
If hasLoggedUser = False And InStr(encoding.GetString(buffer), "login:") Then
'Send User
Dim sendBuffer() As Byte = encoding.GetBytes("my user" & vbCr)
netstream.Write(sendBuffer, 0, sendBuffer.Length)
Console.WriteLine("SENT: {0}", encoding.GetString(sendBuffer))
hasLoggedUser = True
ElseIf hasLoggedPass = False And InStr(encoding.GetString(buffer), "Password:") Then
'Send Pass
Dim sendBuffer() As Byte = encoding.GetBytes("my password" & vbCr)
netstream.Write(sendBuffer, 0, sendBuffer.Length)
Console.WriteLine(" SENT: {0}", encoding.GetString(sendBuffer))
hasLoggedPass = True
ElseIf hasLoggedPass And hasLoggedUser Then
'here is where you can get the prompt and do your cd and whatever. you can do it all at once but i don't recommend it. You sould wait for a response.
Console.WriteLine("All done...")
Exit Do
End If
Loop
Console.Read()
End Sub