FTP in C: 331 / 530 Please specify password -
i have issue sending pass command in c, writing simple program connects ftp server , prints out list stdout.
/* ----------- set connection ---------*/ //creating socket if((sock=socket(af_inet,sock_stream,0))<0) { perror("main: creating socket:"); return error; } //zero out addr memset(&addr, 0, sizeof(addr)); //getting host name hptr=gethostbyname(url.host); if(hptr==null) { perror("error while getting host name:"); return error; } //setting addr connect addr.sin_addr.s_addr = inet_addr(inet_ntoa(*((struct in_addr *)hptr->h_addr_list[0]))); addr.sin_family = af_inet; addr.sin_port = htons(url.port); if((connect(sock, (struct sockaddr *)&addr, sizeof(struct sockaddr))) < 0) { perror("error: connect socket :"); close(sock); return error; } //wait service ready bzero(buffer, maxbuf); if(recv(sock, buffer, sizeof(buffer),0)<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))<0) { perror("error while sending socket:"); } //receive answer if((recv(sock, buffer, sizeof(buffer),0))<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))<0) { perror("error while sending socket:"); } //receive response if((recv(sock, buffer, sizeof(buffer),0))<0) { perror("error while recieving socket:"); } printf("%s", buffer); close(sock); return ok;
now succesfully parse adress in launch parameter.
and succesfully connect want to: 220 back.
after sending char *buffer[1024]; contains: "user anonymous\r\n" or "user anonymous\n" ftp response 331 please specify password.
after try send: "pass secret\r\n" or "pass secret\r\n" , 530
the username anonymous , password secret. tested using ftp , connect sending pass wrong? or doing whole communication wrong?
try using \r\n line end, e.g. write in explanation unlike in code.
Comments
Post a Comment