This module has an embedded TCL interpreter, and offers several facilities based on TCL language.
The main feature is to add a protocol for hooks, it means that instead of giving the path to an executable (or script) in a cscript directive or in a custom site command, you can use a TCL script with direct access to server internals
TCL is provided as a module, keeping main server from adding many useless dependancies.
Just add the line
module = /path/to/libwzd_tcl.soin your config file.
You must ensure that the tcl shared library (for ex libtcl8.4.so, or tcl8.4.dll) is accessible (in the PATH or in the same directory), or module loading will fail.
ftp2sys "path" ( wzdftpd > 0.3.2 )
Converts the path for the current user (relative to the ftp homedir) to an absolute filename (for the system).
ftp2sys "/upload"
Note that the returned path can be different for different users, if they have different home directories.
putlog level "message" ( wzdftpd > 0.3.2 )
Put the message in log file, only if level is greater or equal to the current loglevel. level is an integer in range 0 to 10, 0 is the lowest level (reserved to debug) and 10 is reserved to critical error messages. default level is 5
putlog 5 "zipscript: file is corrupted"
send_message
Use the string given in argument to send reply to client.
You should send one line at a time.
send_message_raw
Sends the string given in argument to client, without any processing. It must be a valid FTP reply.
This function must be use with care.
Example:
send_message_raw "200-test line\r\n"
If reply is complete, script must set variable wzd_reply to "1" to indicate that reply has been completed.
vars get/set variable_name [value]
This function gives access to server internal variables. Use the 'get' method to read variables, the 'set' method to change variables (you need to provide a new value).
See Config variables
vars_group get/set groupname variable_name [value]
This function gives access to group variables. Use the 'get' method to read variables, the 'set' method to change variables (you need to provide a new value).
See Group variables
vars_user get/set username variable_name [value]
This function gives access to user variables. Use the 'get' method to read variables, the 'set' method to change variables (you need to provide a new value).
Note that this concern variables for user definition, and not for connected users: for example, you can't get the current ip (this has a sense only for connected users).
See User variables
vfs mkdir/rmdir dirname
Create or remove a directory. Directory name must be an absolute path !.
vfs read [-r/--real] filename/dirname ( wzdftpd > 0.3.2 )
Get infos on file or directory. File path is inside FTP, unless you specify the -r option, in this case this is an absolute path. Returned string has format:
"user/group/mode"User and group are names (or "unknown"), and mode is the octal number corresponding to file permissions.
vfs link create dirname linkname
Create a symbolic link linkname to the existing directory dirname. Both paths are relative to user homedir (so, "." is the user current directory, and / is the homedir of the current user).
vfs link create [-r/--real] dirname linkname ( wzdftpd > 0.3.2 )
This function is identical to the precedent, except that dirname is given for filesystem (so it must be an absolute path).
vfs link create -r c:\real lnk
vfs link remove [-r/--real] linkname ( wzdftpd > 0.3.3 )
Remove a symbolic link (path is relative to user homedir).
wzd_reply_code
Use this variable contains the current reply code used by server. This is used for custom replies (see send_message_raw). This must be used with caution.
The following example will teach you how to create a tcl script that is called after each file upload, and checks if zip files are valid by calling an external application (not provided here).
##for wzdftpd community ##simple .zip checker ## ## ##Put in wzd.cfg under 'cscript' ##cscript = POSTUPLOAD tcl:c:/wzdftpd/scripts/zip_check.tcl %username %usergroup {%filepath} ## ## ##set path to unzip.exe set binary(UNZIP) "./scripts/unzip.exe" ## ## ##main proc proc zip_check {} { global binary wzd_args regsub -all -- {\"} $wzd_args {} wzd_args set user [lindex [split $wzd_args] 0] set group [lindex [split $wzd_args] 1] if {[string match -nocase *.zip [lindex $wzd_args 2]]} { catch {exec $binary(UNZIP) -qqt [lindex $wzd_args 2]} zipped if {$zipped != ""} { catch {file rename -force -- [lindex $wzd_args 2] [lindex $wzd_args 2].bad} send_message "+----------------------------------------------------" send_message "$user\($group\) uploaded BAD zip file '[file tail [lindex $wzd_args 2]]'." send_message "+----------------------------------------------------" } else { send_message "+----------------------------------------------------" send_message "$user\($group\) uploaded GOOD zip file '[file tail [lindex $wzd_args 2]]'." send_message "+----------------------------------------------------" } } } zip_check