title: Send command to FTP server using sockets in C
body: <p>I am new to socket programing. I want to login to my ftp server. I can establish connection successfully but I can't send other commands for user and password.</p>
  
  <pre><code>#include &lt;sys/socket.h&gt;
  #include &lt;sys/types.h&gt;
  #include &lt;netinet/in.h&gt;
  #include &lt;netdb.h&gt;
  #include &lt;stdio.h&gt;
  #include &lt;string.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;unistd.h&gt;
  #include &lt;errno.h&gt;
  #include &lt;arpa/inet.h&gt;
  
  int main(int argc, char *argv[])
  {
      argv[0]="2";
      argv[1]="00.00.00.0000"; //my ip
  
      int sockfd = 0, n = 0;
      char recvBuff[1024];
      struct sockaddr_in serv_addr;
      char message[100]="USER ftpuser@domain.com";
  
      argc=2;
  
      if(argc != 2)
      {
          printf("\n Usage: %s &lt;ip of server&gt; \n",argv[0]);
          return 1;
      }
  
      memset(recvBuff, '0',sizeof(recvBuff));
      if((sockfd = socket(AF_INET, SOCK_STREAM, 0)) &lt; 0)
      {
          printf("\n Error : Could not create socket \n");
          return 1;
      }
  
      memset(&amp;serv_addr, '0', sizeof(serv_addr));
  
      serv_addr.sin_family = AF_INET;
      serv_addr.sin_port = htons(21);
  
  
      serv_addr.sin_addr.s_addr = inet_addr(argv[1]);
  
      if( connect(sockfd, (struct sockaddr *)&amp;serv_addr, sizeof(serv_addr)) &lt; 0)
      {
          printf("\n Error : Connect Failed \n");
          return 1;
      }
  
      if( send(sockfd , message , strlen(message) , 0) &lt; 0)
      {
          perror("send failed");
          return 1;
      }
  
  
      while ( (n = read(sockfd, recvBuff, sizeof(recvBuff)-1)) &gt; 0)
      {
          recvBuff[n] = 0;
          if(fputs(recvBuff, stdout) == EOF)
          {
              printf("\n Error : Fputs error\n");
              return 0;
          }
      }
  
      if(n &lt; 0)
      {
          printf("\n Read error \n");
          return 0;
      } 
  
      return 0;
  }
  </code></pre>
  
  <p>I am getting this:</p>
  
  <pre><code>220---------- Welcome to Pure-FTPd [privsep] [TLS] ----------
  220-You are user number 1 of 50 allowed.
  220-Local time is now 22:05. Server port: 21.
  220 You will be disconnected after 15 minutes of inactivity.
  </code></pre>
  
  <p>Why I can't send commands to server after connection established?</p>