write a client, of FTP using passive mode. After the data socket for transmission is established, how does the socket for the command inform data socket??
//
int client_data_socket = get_client_data_socket(client_cmd_port);
sprintf(send_buffer, "PASV\r\n");
send_cmd(client_socket, send_buffer);
// 227
length = get_respond(client_socket, recv_buffer, argv[1]);
if (!is_correct_respond(recv_buffer, 227))
{
printf("enter passive mode failed\n");
continue;
}
unsigned int server_data_port = cal_data_port(recv_buffer); //
connect_server(client_data_socket, argv[1], server_data_port);
sprintf(send_buffer, "LIST %s\r\n", "");
send_cmd(client_socket, send_buffer);
// 125 226
length = get_respond(client_socket, recv_buffer, argv[1]);
if (!is_correct_respond(recv_buffer, 125))
{
printf("LIST start failed\n");
continue;
}
// ...
my idea:
client_socket (socket used to accept commands) just use get_respond , block there, wait until receiving the 226command, and client_data_socket should start a process or thread, client_data_socket should also be changed to non-blocking (otherwise it will block if you can"t read the data), when the client_socket sends to end the command, return the data