🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: es.comp.os.linux.programacion
Article #11671

Sockets en c++

#11671
From: skalvin
Date: Tue, 16 Oct 2001 19:23
90 lines
3626 bytes
Hola otra vez!
Tengo un problema con un programa que estoy haciendo en C++ para
conectarme con un servidor FTP (exactamente el proFTP de mi m�quina). 
Bueno el caso es que conectar se conecta bien, pero al enviar el usuario 
y dem�s, ya no avanza. Esto es lo que he hecho:

...
#define PORT 21
#define MAXDATASIZE 300
...
int main(int argc, char *argv[])
{
	...
	int sockfd,  numbytes;
        /* Buffer donde se reciben los datos */
        char buf[MAXDATASIZE];

        char user[X]="usuario"; //X= n� de d�gitos que tiene el usuario
        char pass[X]="contrase�a"; //X=n�de dig. de la contrase�a

        struct sockaddr_in their_addr;
        if ((sockfd = socket(AF_INET, SOCK_STREAM, 0)) == -1)
        {
                perror("socket");
                exit(1);
        }

        their_addr.sin_family = AF_INET;  
        their_addr.sin_port = htons(PORT);
        their_addr.sin_addr.s_addr = inet_addr("192.168.1.1");

        /* Intentamos conectarnos con el servidor */
        if (connect(sockfd, (struct sockaddr *)&their_addr,sizeof(struct sockaddr)) == -1)
        {
                perror("connect");
                exit(1);
        }

        /* Recibimos los datos del servidor */
        if ((numbytes=recv(sockfd, buf, MAXDATASIZE, 0)) == -1)
        {
                perror("recv");
                exit(1);
        }
        /* Visualizamos lo recibido */
        buf[numbytes] = '\0';
        printf("Recivido: %s\n",buf);

       /* Mandamos por el socket el USER */
        if (write(sockfd,user,sizeof(user),0) > 0)
                printf("\n USER Enviado OK \n");
         /* Recibimos los datos del servidor */
        if ((numbytes=read(sockfd, buf, MAXDATASIZE, 0)) == -1)
        {
                perror("recv");
                exit(1);
        }
        /* Visualizamos lo recibido */
        buf[numbytes] = '\0';
        printf("Recivido: %s\n",buf);

        /* Mandamos por el socket el PASS */
        if (send(sockfd,pass,sizeof(pass),0) > 0)
              printf("\n PASS Enviado OK \n");
         /* Recibimos los datos del servidor */
      	 if ((numbytes=recv(sockfd, buf, MAXDATASIZE, 0)) == -1)
        {
                perror("recv");
                exit(1);
        }
        /* Visualizamos lo recibido */
        buf[numbytes] = '\0';
        printf("Recivido: %s\n",buf);

        close(sockfd);
        return 0;
}


Compila perfectamente. Al ejecutarlo esto es lo que pasa:
skalvin@BASAJAUN:~$ ./cliente
Recivido: 220 ProFTP 1.2.0pre10 Server (Debian) [BASAJAUN]

 USER Enviado OK

Y aqu� se queda.

Alguna idea?

PD: acabo de empezar a programar con sockets en linux
Technical Details
Message-ID: <9qi1if$o126k$1@ID-83805.news.dfncis.de>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!newsfeed.stanford.edu!newsfeeds.belnet.be!news.belnet.be!fr.usenet-edu.net!usenet-edu.net!fu-berlin.de!uni-berlin.de!213-99-198-7.uc.nombres.ttd.ES!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Language: SPANISH,ASCII
X-Google-Thread: f86c8,c6402803ae6cf871,start
X-Google-Attributes: gidf86c8,public
X-Google-ArrivalTime: 2001-10-16 12:25:11 PST
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!newsfeed.stanford.edu!newsfeeds.belnet.be!news.belnet.be!fr.usenet-edu.net!usenet-edu.net!fu-berlin.de!uni-berlin.de!213-99-198-7.uc.nombres.ttd.ES!not-for-mail
From: "skalvin" <skalvinANTISPAM@antisocial.com>
Newsgroups: es.comp.os.linux.programacion
Subject: Sockets en c++
Date: Tue, 16 Oct 2001 21:23:58 +0200
Lines: 90
Message-ID: <9qi1if$o126k$1@ID-83805.news.dfncis.de>
NNTP-Posting-Host: 213-99-198-7.uc.nombres.ttd.es (213.99.198.7)
Mime-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 8bit
X-Trace: fu-berlin.de 1003260305 25200852 213.99.198.7 (16 [83805])
X-Orig-Path: not-for-mail
User-Agent: Pan/0.9.7 (Unix)