I have to create the FTP Client programm in C using only sockets. I made this :

Code:
    #include <winsock.h>
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>

    WSADATA WSAData;
            char user[] = "anonymous\n";
            char password[] = "test@test.com";
            char reply[3];
            SOCKET sock;                                                    //socket descriptor
            SOCKET dataSocket;                                      //data socket descriptor
            struct sockaddr_in ftpServAddr;                                 //
            struct sockaddr_in dataServAddr;
            struct hostent *clientAdress;
            unsigned short  ServerControlPort = 21;
            unsigned short  DataPort;
            unsigned short  ClientControlPort;
            unsigned short  ClientDataPort;
            char *adress ="ftp.60free.ovh.org";
            char *hostname;
            char code[2] ;
            int kod_bledu;
            char buf[1000];

    // funkcja sprawdzajaca odpowiedz serwera

    int reply_c(bufa)
    {
        memset(&buf, 0, sizeof(buf));
        if (recv(sock, buf, sizeof(buf), 0) == -1) printf("RECV ERROR");
        char *code =(char*) malloc(3);

        strncpy(code,(char*)bufa,3);
        kod_bledu=atoi(code);

        printf("\nSERVER RESPONSE: %d\n", kod_bledu);
        printf("%s",buf);

        return(kod_bledu);
    }
    //wysylanie polecen do serwera

    int komenda(char *command)
    {
        if (send(sock, command, strlen(command), 0) == -1) printf("blad wysylania");
        reply_c(buf);
    return (0);

    }

  int passive()
  {

 //char buf[1000]="88,79,125,53,233,48";    int i,j,k;
 komenda("PASV\n");
   int i,j,k;
    int a,b,pomocnicza=0;
    int tab[3];
    char tmp[5];
    //printf("%s",buf);

    for(tab[0]=0;tab[0]<1000;tab[0]++)

      if((buf[tab[0]]=='\0') || (buf[tab[0]] == ')'))break;
                k=tab[0];
        for(j=1;j<3;j++)
                        for(;k>=0;k--)
                              if(buf[k]==','){
                              tab[j]=k;
                              k--;

                              break;                              }
for(k=0;k<2;k++){
strncpy(tmp,&buf[tab[k+1]+1],tab[k]-tab[k+1]);
pomocnicza++;

if (pomocnicza==1) a=atoi(tmp);
if (pomocnicza==2) b=atoi(tmp);tmp[tab[k]-tab[k+1]-1]=0;}

//printf("%s\n",tmp);
b=atoi(tmp);
printf("p1:%d p2:%d",b,a);
DataPort = b*b+a;
printf("\nWyliczony DATAPORT %d\n",DataPort);

memset(&dataServAddr, 0, sizeof(dataServAddr));         /* Zero out structure */
        dataServAddr.sin_family         = AF_INET;              /* Internet address family */
        dataServAddr.sin_addr.s_addr    = htonl(INADDR_ANY);       /* Server IP address */
        dataServAddr.sin_port           = htons(DataPort);                 /* Server port */
        
         bind(dataSocket,(struct sockaddr *) &dataServAddr, sizeof(dataServAddr));
        listen(dataSocket,1);
    return 0;

}
    int login()
    {

        do
        {
            reply_c(buf);

           if(kod_bledu == 220)  {
            //    printf("Logowanie anonimowe...\n");
                komenda("USER karol69\n");

             //   reply_c(buf);
             }

            if(kod_bledu == 331) {
            printf("Password needed\n");
            usleep(1000);
            komenda("PASS *******\n");

          //  reply_c(buf);
            }
            if (kod_bledu == 230)

            printf("\nZALOGOWANO DO FTP!\n");}

            while (kod_bledu !=230);
            getchar();
            system("cls");
            return 0;

    }
    int main(int argc, char ** argv)
    {
            printf("      ::::::::::::::::........KLIENT FTP........::::::::::::::\n\n");

            printf("INICJALIZUJE WINSOCKA...\n");

            if( WSAStartup( MAKEWORD( 2, 0 ), &WSAData ) != NO_ERROR )
        {
            printf( "Blad inicjalizacji WinSock2\n" );
            return( 1 );
        }

            if ((sock = socket(PF_INET,SOCK_STREAM, IPPROTO_TCP)) == -1)
            {
                    printf ("Nie moge utworzyc socketa !");
            }

            //data socket
            if((dataSocket = socket(PF_INET, SOCK_STREAM,0))== -1 )
            {
                    printf ("Blad tworzenia data socketa!");
            }
            //konstruowanie struktury server adress

        clientAdress = gethostbyname(adress);
        memset(&ftpServAddr, 0, sizeof(ftpServAddr));
        memcpy(&ftpServAddr.sin_addr, clientAdress->h_addr, clientAdress->h_length);
        ftpServAddr.sin_family         = AF_INET;                 /* Internet address family */
        ftpServAddr.sin_port           = htons(ServerControlPort);      /* Server port */

    //laczenie z socketem


        

        if ( connect(sock, (SOCKADDR*) &ftpServAddr, sizeof(ftpServAddr)) == -1)
        {
            printf("Blad polaczenia!");
        }
        else
        {
            printf("Connect ok!\n");
        }


       



           // system("cls");

          login();
  passive();



          komenda("CDUP\n");
          komenda("PWD\n");

         komenda("SYST\n");

          komenda("PWD\n");


        //  komenda("LIST\n");
         //komenda("NLST\n");

          getchar();
          closesocket(sock);
          closesocket(dataSocket);
          WSACleanup();

    return (0);
    }
I can log on FTP server, I can send commands like PWD, CDUP etc, but I can't send comand LIST or NLST. I don't know how to write Datasocket which data can be transferred. I need help