title: FTP in C: 331 / 530 Please specify password
body: <p>I have an issue sending Pass command in C, i am writing a simple program that connects to an ftp server and prints out LIST to stdout.</p>
  
  <pre><code>/* -----------  SET UP CONNECTION ---------*/
  //creating socket
  if((sock=socket(AF_INET,SOCK_STREAM,0))&lt;0)
  {
      perror("Main: Creating socket:");
      return ERROR;
  }
  
  //Zero out addr
  memset(&amp;addr, 0, sizeof(addr));
  
  //Getting host name
  hPtr=gethostbyname(url.host);
  if(hPtr==NULL)
  { 
      perror("Error while getting host name:");
      return ERROR;
  }
  
  //Setting up addr for connect
  addr.sin_addr.s_addr = inet_addr(inet_ntoa(*((struct in_addr *)hPtr-&gt;h_addr_list[0])));
  
  addr.sin_family = AF_INET;
  addr.sin_port = htons(url.port);
  if((connect(sock, (struct sockaddr *)&amp;addr, sizeof(struct sockaddr))) &lt; 0)
  {
      perror("Error: Connect socket :");
      close(sock);
      return ERROR;
  }
  
  //Wait for Service ready
  bzero(buffer, MAXBUF);
  if(recv(sock, buffer, sizeof(buffer),0)&lt;0)
  {
          perror("Error while receiving socket:");
  }
  
  printf("%s", buffer);
  
  /* -----     LOGIN USER     -----------*/
  bzero(buffer, MAXBUF);
  //setup login
  strcpy(buffer,"USER ");
  strcat(buffer,url.user);
  strcat(buffer,"\n");
  
  //Send login
  if((send(sock,buffer,MAXBUF,0))&lt;0)
  {
      perror("Error while sending socket:");
  }
  //Receive answer
  if((recv(sock, buffer, sizeof(buffer),0))&lt;0)
  {
      perror("Error while recieving socket:");
  }
  printf("%s", buffer);
  
  
  //Send password
  bzero(buffer, MAXBUF);
  //setup password
  strcpy(buffer,"PASS ");
  strcat(buffer,url.pass);
  strcat(buffer,"\n");
  printf("%s",buffer);
  //Send password
  
  if((send(sock,buffer,MAXBUF,0))&lt;0)
  {
      perror("Error while sending socket:");
  }
  //Receive response
  
  if((recv(sock, buffer, sizeof(buffer),0))&lt;0)
  {
      perror("Error while recieving socket:");
  }
  printf("%s", buffer);
  
  close(sock);
  return OK;
  </code></pre>
  
  <p>Now I succesfully parse the adress I get in the launch parameter.</p>
  
  <p>and I succesfully connect where I want to: I get the 220 back.</p>
  
  <p>After sending
  char *buffer[1024];
  which contains: "USER anonymous\r\n" or "USER anonymous\n"
  I get the FTP response 331 please specify the password.</p>
  
  <p>after that I try to send: "PASS secret\r\n" or "PASS secret\r\n"
  and I get 530</p>
  
  <p>the username is anonymous and password is secret. I tested it using ftp and I could connect
  am I sending the pass wrong? or am I doing the whole communication wrong?</p>