Loading FTP file from memory in C

I am programming firmware in C (not C ++) that allows me to transfer a file to ftp (some data that specific hardware has), but I don't seem to know how to do the transfer. This is my code:

    ///pasive connection FTP
    sprintf(szBuf, "PASV\r\n");
        FTP_SendCmd(szBuf);

        if(!FTP_RecvResponse())
            return FALSE;

        if(strncmp(szBuf , "227", 3) != 0)
            return FALSE;



        sprintf(szBuf, "STOR m4.html\r\n");//command that allows storage of a file in the FTP
                FTP_SendCmd(szBuf);
                if(!FTP_RecvResponse())
                                return FALSE;

                if(!FTP_RecvResponse())
                    return FALSE;

      

The thing is, STOR uses the filename, but since this is custom hardware I need a way to stream bytes from a specific address to SDRAM (for example 0x000-0xFFF

), so I was wondering if anyone could give me some advice on how to create the file , fill out the information on FTP?

+3


source to share


1 answer


FTP works with two different connections, the control connection and the data connection. Depending on the mode, the data connection can be initiated by either the server (active) or the client (passive).

The command response PASV

(which indicates passive transmission) contains the IP address and PORT that the server listens for for data connections.

The command STOR

tells the server whose filename should be used to store the data sent by the client over the data connection.

So what are you missing here:



  • Analysis of the response PASV

  • Opening a data connection and sending data over it

There are other exchanges between client and server, for example to coordinate the completion of a data connection after transmission. The protocol is described in RFC 959 .

Without knowing which library you are using, it is difficult to tell how this should be implemented.

A step-by-step overview can be found here

+2


source







All Articles