Home |
Function ftpcli_xfer |
Function ftpcli_xferFunction ftpcli_xfer performs a complete file transfer to/from the FTP server. int ftpcli_xfer(struct ftpcli * cc, char * filename, int isput, int (* user_function)(void * user_pointer, BYTE * buffer, int bufflen), void * user_pointer); ParametersccPointer to the session context established in ftpcli_connect. filenamePointer to the name of the remote file to put or get. isputSet to 0 to get the file, 1 to send it, 2 to append to the remote file. user_functionCallback function to store/retrieve the transferred data. user_pointerOpaque pointer to be passed to user_function. return valuePossible return values for this function are:
user_function is called with these arguments: Parametersuser_pointerThis value is for application use. It is the value passed to ftpcli_xfer, parameter user_pointer. bufferPointer to the I/O buffer of the current transfer. bufflenSize of the buffer pointed to by buffer. return valueThe user function must return one of these values:
ftpcli_xfer is used to send, receive, or append (GET, PUT, or APPEND) files from/to the server. All connection management issues are handled internally. When sending, a user provided function is called repeatedly and the returned data is sent to the server until the user function returns 0 (no more data). If the user function returns -1, the transfer is aborted. When receiving, the routine repeatedly retrieves data from the server and calls the user function with a pointer to the data and a count of bytes to write. If the user function can't write the data, it should return -1 and the transfer will be aborted. This function allocates two TCP sockets, one to listen for a connection from the server and a second socket which is returned by accept and used for data transfer. It is not required to use this function with a true file system. The user function may do anything it wishes as long as the API is followed. For example, a PUT operation could dump the contents of a memory array to a remote file. A GET operation could retrieve a parameter file from the server and parse it on the fly or it could program a boot image into a flash bank.
|