I am writing FTP client program in C. I am use blocking socket. I have put recv () in while loop and I break it when last two received characters are \r\n. I am able to run it on some servers but it doesn't read whole message on some servers like ftp.secyt.gov.ar.
I think the problem is because of the messages from server which contains characters \r \n together.
How should I deal with such case?
After sending the user name and password to server at ftp.secyt.gov.ar, I want to print the message received from server.
password = getpass("Password: ");
sprintf(pass, "PASS %s\r\n",password);
send(sockfd, pass, strlen(pass), 0);
while((no_of_bytes = recv(sockfd, message_from_server, MAXSZ, 0)) > 0)
{
message_from_server[no_of_bytes] = '\0';
printf("%s\n", message_from_server);
if (message_from_server[no_of_bytes-2] == '\r' &&
message_from_server[no_of_bytes-1] == '\n')
break;
}
Server sends this message:
230-=====================================================================
BIENVENIDOS AL SERVIDOR FTP DE LA MINCyT
----------------------------------------
Usuario anonymous, desde la maquina ::ffff:116.203.73.60, gracias por
utilizar el FTP del Ministerio de Ciencia, Tecnologia e
Innovacion Productiva.
Para sugerencias, consultas o informacin adicional nuestros correos
electrnicos son:
webmaster@mincyt.gov.ar
=========================================================================
230 User anonymous logged in.
But it is printing only:
230-=====================================================================