Contents:

Overview








:


FTP module:
Features:
- FTP server
- Callback for each action
- Return data from the host program.
- Return regular files
- Store files from clients.
- It is DLL.

Usage




This is FTP server.
For it just call SetFTPServer. The callback function may call for any actions that income from client.
The host program may just return zero by this callback, and in this case the server will work by default.
The host program may return the code , and in this case the code will be translated to client.
The host program may reply to the client itself with help SRVSend or SRVprintf functions. The actions
ACTION_DOWNLOAD, ACTION_UPLOAD, ACTION_DIR request data connection and the host program would like to work
the request it must use SRVCreateData, then SRVDSend, SRVDprintf to send or SRVDRecv to receive the data.
After transfer the host program call SRVEndData




Functios








type of stream
typedef void * ServerStream;



FTPReqCallback
type for callback function that will call for each request, after request received, before server do anything other.
typedef int (* FTPReqCallback)(ServerStream * stream, char * reqname, int action, ...);
Parameters:
The stream may be used by host program for next request.
The reqname it is name of requested file.
The action defined there: ACTION_LOGIN ACTION_DOWNLOAD ACTION_UPLOAD ACTION_DIR ACTION_MKDIR ACTION_RENAME ACTION_REMOVE ACTION_LOGOUT
Return value:
If this callback return zero, the server will still work the request.
If this callback return subzero the server understand that host program
If this callback return value above zero, the server return it to client as error code and return error page.

ALL_ACTIONS


SetFTPServer
The host program must only call SetFTPServer function, that create server thread
int SetFTPServer(FTPReqCallback callback=NULL, int port=0, int mask=ALL_ACTIONS);
Parameters:
The callback -- callback function that will call for each request, after request received, before server do anything other
by default NULL -- int this case the server will just work with request.
The port -- TCP/IP port. If used default value zero, the server use value from config, by default 21.
mask -- the mask for action for that the server call callback
Return value:
Zero if success.
Subzero if fail



SRVCreateData
Some actions (DIR,UPLOAD,DOWNLOAD) required to create data connection. For it you may use next function:
int SRVCreateData(ServerStream * stream);
Parameters:
The stream -- pointer to stream that was transfer to callback function.
Return value:
Zero if success.
Subzero if fail

SRVEndData
Data connection must by closed after transfer. For it you may use next function.
int SRVEndData(ServerStream * stream);
Parameters:
The stream -- pointer to stream that was transfer to callback function.
Return value:
Zero if success.
Subzero if fail



SRVSend
The host program may send data to the client CONTROL connection with next functions:
int SRVSend(ServerStream * stream, void * bufer, int size);
Parameters:
The stream -- pointer to stream that was transfer to callback function.
The bufer -- bufer to send
The size -- size of buffer
Return value:
Number of bytes that has been send.
Zero if error

SRVprintf

int SRVprintf(ServerStream * stream, char * format, ...);
Parameters:
The stream -- pointer to stream that was transfer to callback function.
The format -- format like in stdio printf
... params by format
Return value:
Number of bytes that has been send.
Zero if error



SRVDSend
The host program may send data to the client DATA connection with next functions:
int SRVDSend(ServerStream * stream, void * buffer, int size);
Parameters:
The stream -- pointer to stream that was transfer to callback function.
The buffer -- buffer to send
The size -- size of buffer
Return value:
Number of bytes that has been send.
Zero if error
SRVDprintf

int SRVDprintf(ServerStream * stream, char * format, ...);
Parameters:
The stream -- pointer to stream that was transfer to callback function.
The format -- format like in stdio printf
... params by format
Return value:
Number of bytes that has been send.
Zero if error

SRVDRecv
If you would like reveive the data st you may use SRVDRecv:
int SRVDRecv(ServerStream * stream, void * buffer, int l);
Parameters:
The stream -- pointer to stream that was transfer to callback function.
The buffer -- buffer to receive
The size -- size of buffer
Return value:
Number of bytes that has been receive.
Zero if error




GetAUTHName
To get info about authorization use next functions:
char * GetAUTHName(ServerStream * stream);
Parameters:
The stream -- pointer to stream that was transfer to callback function.
Return value:
pointer to user name.
GetAUTHPassw
The NULL pointer if no control present.
char * GetAUTHPassw(ServerStream * stream);
Parameters:
The stream -- pointer to stream that was transfer to callback function.
Return value:
pointer to password.
The NULL pointer if no control present.



GetRemoteIP
Advanced info about connection you may get with next functions.
ulong GetRemoteIP(ServerStream * stream);
Parameters:
The stream -- pointer to stream that was transfer to callback function.
Return value:
IP address of remote.

GetRemoteAddr

int GetRemoteAddr(void * addr, int buflen);
Parameters:
The stream -- pointer to stream that was transfer to callback function.
Return value:
address of remote in sockaddr struct
GetSocket

int GetSocket(ServerStream * stream);
Parameters:
The stream -- pointer to stream that was transfer to callback function.
Return value:
socket


The host program may load all params for module from separate file,
LoadConfig
or my set required params directly, or use default values.
int LoadConfig(char * filename="ftp.cfg");
Parameters:
The filename -- name of configuration file.
Return value:
Zero if success.
Subzero if fail


SetConfigParam
You may set all params directly:
void SetConfigParam(char * param, int val);
Parameters:
The param -- name of param
val -- value.
SetConfigParam

void SetConfigParam(char * param, char * val);
Parameters:
The param -- name of param
val -- value.

To get current values of configuration params you may use next functions:
GetConfigParamInt
For integer params:
int GetConfigParamInt(char * param);
Parameters:
The param -- name of param

SetConfigParamStr
For string params:
char *SetConfigParamStr(char * param);
Parameters:
The param -- name of param