I'm implementing a very simple FTP server program that is able to retrieve and store text files. my question is, when a ftp client request say a file with the following "RETR test.txt" how does the server send this file?. Does it open that text file copy the contents into a buffer and simply send it or is there more to it?. I'm not sure how to implement this, could someone clarify the basic idea?.
edit::
if (strncmp(receive_buffer,"RETR",4)==0) {
sprintf(send_buffer,"150 Opening ASCII mode data connection... \r\n");
printf("<< DEBUG INFO. >>: REPLY sent to CLIENT: %s\n", send_buffer);
bytes = send(ns, send_buffer, strlen(send_buffer), 0);
if (bytes < 0) break;
closesocket(ns);
char temp_buffer2[80];
FILE *fin=fopen("test.txt","r");//open test.txt
while (!feof(fin)){
fgets(temp_buffer2,78,fin);
sprintf(send_buffer,"%s",temp_buffer2);
printf("%s",send_buffer);
if (active==0) {
printf("***active is 0");
send(ns_data, send_buffer, strlen(send_buffer), 0);
}
else {
printf("***active is 1+");
send(s_data_act, send_buffer, strlen(send_buffer), 0);
}
}
fclose(fin);
sprintf(send_buffer,"226 File transfer complete. \r\n");
printf("<< DEBUG INFO. >>: REPLY sent to CLIENT: %s\n", send_buffer);
bytes = send(ns, send_buffer, strlen(send_buffer), 0);
if (active==0 )closesocket(ns_data);
else closesocket(s_data_act);
}
this is what I have done, and for the RETR command it opens test.txt to try and send it. But this causes the server to disconnect..