type of stream
typedef void * ServerStream;
StateCallback
type for callback function that may call for notify host about download/upload state..
typedef int (*
StateCallback)(ServerStream *
stream, void *
data, int
state, int
procent, int
total_size);
Parameters:
stream -- pointer to stream that was returned by
SRVOpenUrl
data' -- user s data, the same thst host program set in
SRVOpenUrl
state defined here:
STATE_CONECTING STATE_LOGIN STATE_INITDATA STATE_DOWNLOAD_IN_PROGRESS STATE_UPLOAD_IN_PROGRESS STATE_DONE
procent -- the percentage (if available)
total_size -- the size of requested URL (if available)
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.
SRVOpenUrl
You may open any URL like local file with function:
ServerStream
SRVOpenUrl(char *
url, int
type,
StateCallback callback=NULL, void *
data=NULL, int
post_size=0, char *
user=NULL, char *
passw=NULL, char *
filename=NULL);
Parameters:
The
url -- The URL to get
The
type -- defined here
TYPE_HTTP_GET TYPE_HTTP_POST TYPE_HTTP_FTPDIR TYPE_HTTP_FTPR TYPE_HTTP_FTPW TYPE_FLAG_ASINH
data -- user defined data -- will be transfer to callback function
post_size -- size of POST (if need)
user', 'passw -- authorization data (if need)
filename -- to save URL to local file, direct filename. (if need)
Return value:
If success return the pointer to Stream
NULL if error.
SRVRecv
To receive the data you may use
SRVRecv:
int
SRVRecv(ServerStream *
stream, void *
buffer, int
size);
Parameters:
The
stream -- pointer to stream that was returned by
SRVOpenUrl
The
buffer -- buffer to receive
The
size -- size of buffer
Return value:
Number of bytes that has been receive.
Zero if EOF
SRVSend
The host program may send data to the FTP with next functions:
int
SRVSend(ServerStream *
stream, void *
buffer, int
size);
Parameters:
The
stream -- pointer to stream that was returned by
SRVOpenUrl
The
buffer -- buffer 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 returned by
SRVOpenUrl
The
format -- format like in stdio printf
... params by format
Return value:
Number of bytes that has been send.
Zero if error
SRVClose
After action call
SRVClose to release the resourse.
void
SRVClose(ServerStream *
stream);
Parameters:
The
stream -- pointer to stream that was returned by
SRVOpenUrl
SRVOpenFTP
For FTP full mode provide next interface:
ServerStream
SRVOpenFTP(char *
host, char *
user="anonymous", char *
passw="@");
SRVFTPUploadFile
For upload local file to FTP use
SRVFTPInitUpload :
int
SRVFTPUploadFile(ServerStream *
stream, char *
filename, char *
localfile);
Parameters:
The
stream -- pointer to stream that was returned by
SRVOpenFTP.
filename -- the name of file on remote server
localfile -- the pathname of file on local PC
Return value:
Zero if Ok
Code of error if fail.
SRVFTPDownloadFile
For download local file from FTP use
SRVFTPInitUpload :
int
SRVFTPDownloadFile(ServerStream *
stream, char *
filename, char *
localfile);
Parameters:
The
stream -- pointer to stream that was returned by
SRVOpenFTP.
filename -- the name of file on remote server
localfile -- the pathname of file on local PC
Return value:
Zero if Ok
Code of error if fail.
SRVFTPInitUpload
For begin stream to upload file use
SRVFTPInitUpload :
int
SRVFTPInitUpload(ServerStream *
stream, char *
filename);
Parameters:
The
stream -- pointer to stream that was returned by
SRVOpenFTP.
filename -- the name of file on remote server
Return value:
Zero if Ok
Code of error if fail.
SRVFTPInitDownload
For begin stream to download file use
SRVFTPInitDownload :
int
SRVFTPInitDownload(ServerStream *
stream, char *
filename);
Parameters:
The
stream -- pointer to stream that was returned by
SRVOpenFTP.
filename -- the name of file on remote server
Return value:
Zero if Ok
Code of error if fail.
void SRVFTPEndData(ServerStream *stream)
Parameters:
The
stream -- pointer to stream that was returned by
SRVOpenFTP.
SRVFTPRm
For remove file:
int
SRVFTPRm(ServerStream *
stream, char *
filename);
Parameters:
The
stream -- pointer to stream that was returned by
SRVOpenFTP.
filename -- the name of file on remote server
Return value:
Zero if Ok
Code of error if fail.
SRVFTPchmod
For change file attributes:
int
SRVFTPchmod(ServerStream *
stream, char *
filename, int
mode);
Parameters:
The
stream -- pointer to stream that was returned by
SRVOpenFTP.
filename -- the name of file on remote server
mode -- file attributes: Bits format:
bit: | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
for: | owner | owner | owner | group | group | group | any | any | any |
type: | exec | write | read | exec | write | read | exec | write | read |
MODE_ANY_READ MODE_ANY_WRITE MODE_ANY_EXEC MODE_GROUP_READ MODE_GROUP_WRITE MODE_GROUP_EXEC MODE_OWNER_READ MODE_OWNER_WRITE MODE_OWNER_EXEC
Return value:
Zero if Ok
Code of error if fail.
SRVFTPInitDir
For begin stream to read dir use
SRVFTPInitDir :
int
SRVFTPInitDir(ServerStream *
stream, char *
filename);
Parameters:
The
stream -- pointer to stream that was returned by
SRVOpenFTP.
filename -- the name of file on remote server
Return value:
Zero if Ok
Code of error if fail.
SRVFTPMkDir
For create directory:
int
SRVFTPMkDir(ServerStream *
stream, char *
dir);
Parameters:
The
stream -- pointer to stream that was returned by
SRVOpenFTP.
dir -- the name of directory on remote server
Return value:
Zero if Ok
Code of error if fail.
SRVFTPRmDir
For remove directory:
int
SRVFTPRmDir(ServerStream *
stream, char *
dir);
Parameters:
The
stream -- pointer to stream that was returned by
SRVOpenFTP.
dir -- the name of directory on remote server
Return value:
Zero if Ok
Code of error if fail.
SRVFTPRename
For rename file on remote server
int
SRVFTPRename(ServerStream *
stream, char *
filename_from, char *
filename_to);
Parameters:
The
stream -- pointer to stream that was returned by
SRVOpenFTP.
filename_from -- old name of file on remote server
filename_to -- new name of file on remote server
Return value:
Zero if Ok
Code of error if fail.
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 returned by
SRVOpenFTP.
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 returned by
SRVOpenFTP.
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 *
bufer, int
l);
Parameters:
The
stream -- pointer to stream that was returned by
SRVOpenFTP.
The
buffer -- buffer to receive
The
size -- size of buffer
Return value:
Number of bytes that has been receive.
Zero if error
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