View Single Post
Old 06-06-2003, 02:42 PM  
Luca
Junior Member
 
Join Date: Jun 2003
Posts: 5
Default

Here is what my program do.

I hope the comments are enough for you, so you can help me

Code:
void ftp_passivelist (int *fd)
{
	struct sockaddr_in server; // structure with the info taken from the PASV command (ip & port)
	int p1 = 0, p2 = 0; // integer number containing the port numbers in the internert notation
	int dataC; // socket used for the data connection

	MakeSocket (&dataC); // initialization of the socket

	memset (&server, 0, sizeof (server)); // nothing important

	// used to take the ip and the port from the message returned by the PASV command
	sscanf (buffer, "227 Entering Passive Mode (%d,%d,%d,%d,%d,%d)", &server.sin_addr.S_un.S_un_b.s_b1,
																	 &server.sin_addr.S_un.S_un_b.s_b2,
																	 &server.sin_addr.S_un.S_un_b.s_b3,
																	 &server.sin_addr.S_un.S_un_b.s_b4,
																	 &p1, &p2);

	// just a debug print to see if the info correspond to the reply of the PASV command
	printf ("--> (%d,%d,%d,%d,%d,%d)",	server.sin_addr.S_un.S_un_b.s_b1,
										server.sin_addr.S_un.S_un_b.s_b2,
										server.sin_addr.S_un.S_un_b.s_b3,
										server.sin_addr.S_un.S_un_b.s_b4,
										p1, p2);

	server.sin_port = htons ((p1 * 256) + p2); // the port number
	server.sin_family = AF_INET; // nothing important

	printf (" --> %d\n\n", (p1 * 256) + p2); // another debug print

	send (*fd, "LIST \r\n", 7, 0);	// send of the LIST command \r\n are the telnet end of line

	// connecting to the port specified by the ftp server
	if (connect (dataC, (struct sockaddr *)&server, sizeof (server)) < 0)
		printf ("error connect");

	GetReply (fd);	// receive of the reply to the LIST command from the control connection

	int a;

	// this SHOULD be the receiving of the listing from the data connection and it's printing
	while ((a = recv (dataC, buffer, sizeof (buffer), 0)) > 0)
	{
		printf ("%s", buffer);
	}

	// after i've received the lidting, I close the data connection
#if (defined (_WIN32) || defined (WIN32)) 
	closesocket (dataC);
#else
	close (dataC);
#endif

	printf ("\n\n"); // nothing important

	GetReply (fd);	// receive of the reply to the LIST command after the receiving of the file 
					// listing
}
Luca is offline