I have an app that ftp's some data up to a site. Then using telnet, I need to kick off a process. It would be nice to automate this process, but I run into trouble when I send the commands. The command created and sent is correct, but the receiving server does not get the 'end' command. This is my code:
-------------------------------------------------------
Private Sub Starttelnet()
Dim s, sError As String
s = SocketSendReceive("100.100.100.100", 3000, sError)
Me.TextBox1.Text = s
End Sub
Private Function SocketSendReceive(ByVal server As String, ByVal port As Integer, ByRef sError As String) As String
'Set up variables and String to write to the server.
Dim ascii As Encoding = Encoding.ASCII
Dim request As String = "Begin" + ControlChars.Cr + ControlChars.Lf + "command=DoCommand" + ControlChars.Cr + ControlChars.Lf + "requestfile=upload/filelist1.txt" + ControlChars.Cr + ControlChars.Lf + "end"
Dim bytesSent As [Byte] = ascii.GetBytes(Request)
Dim bytesReceived(1024) As [Byte]
Dim bytes As Int32
Dim page As String
Dim a As Integer
' Create a socket connection with the specified server and port.
Dim s As Socket = ConnectSocket(server, port, sError)
If s Is Nothing Then
Return "Connection failed"
End If
'Send request to the server.
s.Send(bytesSent, bytesSent.Length, 0)
Do
bytes = s.Receive(bytesReceived, bytesReceived.Length, 0)
page = page + ascii.ASCII.GetString(bytesReceived, 0, bytes)
Loop While bytes > 0
Return page
End Function
-------------------------------------------------------
The request string being sent is correct. When I debug, I get:
Begin
command=docommand
requestfile=upload/filelist1.txt
End
However, the response received is:
INF: Connected to xxxxx server
INF: Version 1.0b
INF: Begin with 'begin', end with 'end'.
ACK
INF: Got BEGIN
ACK
INF: Got command: [command=docommand]
ACK
INF: Got command: [requestfile=upload/filelist1.txt]
ERR: Timeout! I didn't hear anything.
INF: Goodbye!
Has anyone ever encountered this issue? I have tried various versions of the request string with no luck.
Please help!
Peter
-------------------------------------------------------
Private Sub Starttelnet()
Dim s, sError As String
s = SocketSendReceive("100.100.100.100", 3000, sError)
Me.TextBox1.Text = s
End Sub
Private Function SocketSendReceive(ByVal server As String, ByVal port As Integer, ByRef sError As String) As String
'Set up variables and String to write to the server.
Dim ascii As Encoding = Encoding.ASCII
Dim request As String = "Begin" + ControlChars.Cr + ControlChars.Lf + "command=DoCommand" + ControlChars.Cr + ControlChars.Lf + "requestfile=upload/filelist1.txt" + ControlChars.Cr + ControlChars.Lf + "end"
Dim bytesSent As [Byte] = ascii.GetBytes(Request)
Dim bytesReceived(1024) As [Byte]
Dim bytes As Int32
Dim page As String
Dim a As Integer
' Create a socket connection with the specified server and port.
Dim s As Socket = ConnectSocket(server, port, sError)
If s Is Nothing Then
Return "Connection failed"
End If
'Send request to the server.
s.Send(bytesSent, bytesSent.Length, 0)
Do
bytes = s.Receive(bytesReceived, bytesReceived.Length, 0)
page = page + ascii.ASCII.GetString(bytesReceived, 0, bytes)
Loop While bytes > 0
Return page
End Function
-------------------------------------------------------
The request string being sent is correct. When I debug, I get:
Begin
command=docommand
requestfile=upload/filelist1.txt
End
However, the response received is:
INF: Connected to xxxxx server
INF: Version 1.0b
INF: Begin with 'begin', end with 'end'.
ACK
INF: Got BEGIN
ACK
INF: Got command: [command=docommand]
ACK
INF: Got command: [requestfile=upload/filelist1.txt]
ERR: Timeout! I didn't hear anything.
INF: Goodbye!
Has anyone ever encountered this issue? I have tried various versions of the request string with no luck.
Please help!
Peter