Send command to FTP server using sockets in C -


i new socket programing. want login ftp server. can establish connection can't send other commands user , password.

#include <sys/socket.h> #include <sys/types.h> #include <netinet/in.h> #include <netdb.h> #include <stdio.h> #include <string.h> #include <stdlib.h> #include <unistd.h> #include <errno.h> #include <arpa/inet.h>  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 <ip of server> \n",argv[0]);         return 1;     }      memset(recvbuff, '0',sizeof(recvbuff));     if((sockfd = socket(af_inet, sock_stream, 0)) < 0)     {         printf("\n error : not create socket \n");         return 1;     }      memset(&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 *)&serv_addr, sizeof(serv_addr)) < 0)     {         printf("\n error : connect failed \n");         return 1;     }      if( send(sockfd , message , strlen(message) , 0) < 0)     {         perror("send failed");         return 1;     }       while ( (n = read(sockfd, recvbuff, sizeof(recvbuff)-1)) > 0)     {         recvbuff[n] = 0;         if(fputs(recvbuff, stdout) == eof)         {             printf("\n error : fputs error\n");             return 0;         }     }      if(n < 0)     {         printf("\n read error \n");         return 0;     }       return 0; } 

i getting this:

220---------- welcome pure-ftpd [privsep] [tls] ---------- 220-you user number 1 of 50 allowed. 220-local time 22:05. server port: 21. 220 disconnected after 15 minutes of inactivity. 

why can't send commands server after connection established?

you need terminate each ftp command crlf. missing user command. remote server won't process command until receives newline.

source: rfc 959


Comments

Popular posts from this blog

Payment information shows nothing in one page checkout page magento -

tcpdump - How to check if server received packet (acknowledged) -