Recv

Recv is used to retrieve data from a socket (used for both TCP and UDP transmissions).

Syntax

Recv(SizeInBytes, [DataType])

More Information

The SizeInBytes parameter specifies how much of the buffer will be returned. The optional parameter “DataType” can be used to specify in what format the buffer should be returned. If nothing is specified the buffer is analyzed, and the appropriate DataType will be set accordingly.

Possible options for the DataType parameter are as follow:

  • 0 – Return buffer as an array of bytes (ideal for raw data)
  • 1 – Return Buffer as a string (ideal if you know that the buffer consists of raw text)
  • 2 – Return buffer as string, convert non printable characters into “.” Ideal when you know that the buffer is mixed between plain text and special characters but when you’re just interested in the plain text part.
Returns

String or an array of bytes.

Example

This Script displays the banner of an ftp server that is running locally. It can work with any ftp server by changing the value of the variable "ip":

Function Main

Dim SocketObject As Object

Dim ip As String

Dim port As String

Dim strResponse As String

Ip = "127.0.0.1"

Port = "21"

Socket.SetTimeout 5000,5000

Set SocketObject = Socket.OpenTcp(Ip,Port)

If Not SocketObject is Nothing Then

'check to see that the Object returned successfully

strResponse = SocketObject.Recv(1024)

echo(strResponse)

SocketObject.Close

End If

End Function