manully establish connection to ftp server using sockets

887 views Asked by At

I'm trying to manually receive a file from an ftp server. So far I can connect to the server and check its 220 response but then I want to send the username and wireshark displays tht some random Bytes are being sent out. First my code:

struct request 
    { 
    int reply;                         /* TRUE = request reply from server */  
    int msgLen;                        /* length of message text */ 
    char message[REQUEST_MSG_SIZE];    /* message buffer */  
    };

        ...
        //ESTABLISH SOCKET CONNECTION
        ...

/* send request to server */
strcpy(myRequest.message,"ftp");
myRequest.msgLen = 3; 
if (write (sFd, (char *) &myRequest, sizeof (myRequest)) == ERROR) 
        { 
        perror ("write"); 
        close (sFd); 
        return ERROR; 
        }

if (read (sFd, replyBuf, REPLY_MSG_SIZE) < 0)  { 
    perror ("read"); 
    close (sFd); 
    return ERROR; 
}

// CHECK if ser ver responded with code 220
if (strstr(replyBuf,"220")==NULL) { 
    perror ("Response220"); 
    close (sFd); 
    return ERROR; 
}

// send user name to server 
strcpy(myRequest.message,"USER **");
myRequest.msgLen = 7; 
if (write (sFd, (char *) &myRequest, sizeof (myRequest)) == ERROR) 
        { 
        perror ("write"); 
        close (sFd); 
        return ERROR; 
        }

    if (read (sFd, replyBuf, REPLY_MSG_SIZE) < 0)  { 
        perror ("read"); 
        close (sFd); 
        return ERROR; 
    }


printf ("MESSAGE FROM SERVER:\n%s\n", replyBuf);

but for some reason, I always seem to have some random Bytes in my send string: first, the ftp string looks like this:

36 1.767818000 3.94.213.214 3.94.213.53 FTP 70 Request: \356\356\356\356\000\000\000\003ftp\000"\032\244^

which it can deal with, the server reply:

38 1.777790000 3.94.213.53 3.94.213.214 FTP 74 Response: 220 (vsFTPd 3.0.2)

but then the USER string looks like this:

40 1.781575000 3.94.213.214 3.94.213.53 FTP 70 Request: \356\356\356\356\000\000\000\aUSER **\000

which it, not-surprisingly, can't do much with. After this, I would expect the server to ask me for a password.

The client is running on a VxWorks machine and the server is vsFTP on Linux

1

There are 1 answers

0
Ankit Tripathi On

Why are you sending the struct over the socket, you just need to send the data. Moreover you cannot send the data over the same connection.....once the the first connection that you make with an ftpd is a command connection, when you send data another connection is opened. I guess you need to see FTP RFC 959 before you proceed this way.