Share this page

# FTP correlation (WS)

The following section describes how to correlate the PORT command for use with the FTP protocol.

## Problem

The process of transferring data consists of setting up the data connection to the appropriate ports and choosing the transfer parameters. Both the user and the server-DTPs have a default data port. The user-process default data port is the same as the control connection port (i.e., U). The server-process default data port is the port adjacent to the control connection port (i.e., L-1).

A User-PI may specify a non-default user side data port using the PORT command. In this situation, a different data connection is received each time you connect, and correlation is therefore necessary.

## Solution

The argument of the PORT command is a HOST-PORT specification for the data port to be used in data connection. They are default for both the user and server data ports. The argument is the concatenation of a 32-bit Internet host address and a 16-bit TCP port address. This address information is broken into 8-bit fields and the value of each field is transmitted as a decimal number (in character string representation). Commas separate the fields. A port command would be:

PORT h1, h2, h3, h4, p1, p2

p1 represents the upper 8-bits of the port number

p2 represents the lower 8-bits of the port number.

p1 & p2 were parameterized to the parameter PortNum in Buf10.

1. Get the local port of the local host.

2. Parse the local port to low and high order bits and save them to a variable.

3. Parameterize the port number in the appropriate buffer of the data.ws file.

4. Use lr_save_string to save the variable with the port number to the defined parameter.

## Example

/*********************************************************************

* Created by Windows Sockets Recorder

* Created on: Sat Apr 15 21:55:23

*********************************************************************/

#include "lrs.h"

Actions ()

{

char *NewPort;

char *UserBuf;

char Buf[255];

char Tmp[255];

int iVal, iHighVal, iLowVal;

lr_think_time(12);

lrs_send("socket2", "buf8", LrsLastArg);

lrs_receive("socket2", "buf9", LrsLastArg);

lrs_create_socket("socket3", "TCP", "LocalHost=0",
"Backlog=1", LrsLastArg);

/* Get the Local Port of the Local Host on socket3 */

NewPort = lrs_get_socket_attrib("socket3", LOCAL_PORT );

lr_output_message("Local port %s", NewPort);

/* Parse NewPort to low and high order and save to 'PortNum' parameter */

iVal = atoi (NewPort);

iLowVal = (WORD)(iVal) & 0xFF;

iHighVal = (WORD)(((DWORD)(iVal) >> 8) & 0xFF);

strcpy (Buf, itoa( iHighVal, Tmp, 10 ));

strcat (Buf, ",");

strcat (Buf, _itoa( iLowVal, Tmp, 10 ));

/* Save the PortNum to buf 10.

* send buf10

* "PORT 199,203,74,132,<PortNum>\r\n"

* The first 4 numbers are the IP and the fifth argument must be
* replaced with the new parameter.*/

lr_save_string(Buf, "PortNum");

/* Get the content of Buf10 and print to output for debug */

lrs_get_static_buffer("socket2", "buf10", 0, -1, NULL);

UserBuf = lrs_get_user_buffer("socket2");

lr_output_message("Buf10 Content %s", UserBuf);

lrs_send("socket2", "buf10", LrsLastArg);

lrs_receive("socket2", "buf11", LrsLastArg);

lrs_send("socket2", "buf12", LrsLastArg);

lrs_receive("socket2", "buf13", LrsLastArg);

lrs_set_accept_timeout(30,0);

lrs_accept_connection("socket3", "socket4");

lrs_close_socket("socket3");

lrs_receive("socket4", "buf14", LrsLastArg);

lrs_close_socket("socket4");

lrs_receive("socket2", "buf15", LrsLastArg);

return 0;

}

Tips to improve your search results... VuGen Function Reference Version 25.1-25.3 Function Reference 25.1-25.3 All View Local Help Center View Online Help Center Version: