Navigation:  Advanced Features >

Lua Language

Previous pageReturn to chapter overviewNext page

About Lua


Lua is a powerful, fast, lightweight, embeddable scripting language. Lua combines simple procedural syntax with powerful data description constructs based on associative arrays and extensible semantics. Lua is dynamically typed, runs by interpreting bytecode for a register-based virtual machine, and has automatic memory management with incremental garbage collection, making it ideal for configuration, scripting, and rapid prototyping.


Wing FTP Server includes supporting for Lua scripting. And Lua scripts can be used in several cases, such as Task Scheduler, Event Manager, and Administration Console. It will help you to complete a complex task or a custom event, or just a simple console command.


You can write Lua scripts simply by using standard Lua libraries or Wing FTP Server's Lua API. For example, if you want to add a user account, you can call the API c_AddUser(...) to handle it, and if you want to delete the user account, just call c_DeleteUser(...). It is simple yet powerful.


Simple example (a daily task scheduler for removing inactive users in domain "domain1" who have not logged in within 15 days)

    local strUserlist = c_GetUserList("domain1") 
    local userlist = Split(strUserlist,"\n") 
    for _,username in pairs(userlist) do 
        local user = c_GetUser("domain1",username)
        local logintime = user.last_logintime
        local logintime_t = c_TranslateTime(logintime)
        if (os.time() - logintime_t) >= 3600*24*15 then 




RESTful Web Service


Wing FTP Server also provides a RESTful web service for administration, and you can call it to execute lua scripts in any programming language.


The RESTful web service URL may look like this:'hello,world')

There are three URL parameters in the above URL, the 1st parameter "admin" means the administrator's username, the 2nd parameter "pass" means the administrator's password, and the 3rd parameter "cmd" means the lua scripts (with URL encoded).


For the web service safety, we suggest you use a separated system admin with IP access rules (For example, if 3rd party website has a fixed IP address "", you can add a IP access rule "Allow" under "Add/Edit Admin -> IP access").

Using HTTPS address is also highly recommended when calling the web service, it can mostly avoid data sniffing over the network.


Here is a simple example for calling the web service by the 3rd party website/program, it is used to calculate the number of all the domains' online sessions.



PHP example:

$strUrl = ""
$strUrlParam = "?admin=AdminUser&pass=AdminPass&cmd="
$strLuaScript = <<<EOT 
    local nSessionCnt = 0 
    for _,domain in pairs(c_GetDomainList()) do 
        nSessionCnt = nSessionCnt + c_GetSessionCount(domain) 
$strResult = file_get_contents($strUrl.$strUrlParam.rawurlencode($strLuaScript));




VB script/ASP example:

Set xmlHttp = CreateObject("MSXML2.ServerXMLHTTP"
strUrl = "" 
strUrlParam = "?admin=AdminUser&pass=AdminPass&cmd=" 
strLuaScript = "local nSessionCnt = 0 "
              &"for _,domain in pairs(c_GetDomainList()) do "
              &" nSessionCnt = nSessionCnt + c_GetSessionCount(domain) "
              &"end "
              &"print(nSessionCnt)" "GET", strUrl&strUrlParam&URLEncode(strLuaScript), False 
strResult = xmlHttp.responseText
Function URLEncode(strInput) 
    For i = 1 To Len(strInput) 
        intAscii = Asc(Mid(strInput, i, 1)) 
        If ((intAscii < 58And (intAscii > 47)) Or ((intAscii < 91And (intAscii > 64)) Or ((intAscii < 123And (intAscii > 96)) Then 
            strOutput = strOutput & Chr(intAscii) 
            If intAscii < 16 Then 
                strOutput = strOutput & "%0" & Trim(Hex(intAscii)) 
                strOutput = strOutput & "%" & Trim(Hex(intAscii)) 
            End If 
        End If 
    URLEncode = strOutput 
End Function




JAVA example:

class GetUrlContent { 
    public static void main(String[] args) throws IOException { 
        String strUrl = ""; 
        String strUrlParam = "admin=AdminUser&pass=AdminPass&cmd="; 
        String strLuaScript = "local nSessionCnt = 0 "+ 
                              "for _,domain in pairs(c_GetDomainList()) do "+ 
                              " nSessionCnt = nSessionCnt + c_GetSessionCount(domain) "+ 
                              "end "+ 

        String strResult = SendGetRequest(strUrl,, "UTF-8").replaceAll("\\+", "%20"));
    public static String SendGetRequest(String url, String param) { 
        String result = "";
        try { 
            String urlName = url + "?" + param; 
            URL U = new URL(urlName); 
            URLConnection connection = U.openConnection(); 
            BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream())); 
            String line; 
            while ((line = in.readLine()) != null) { 
                result += line; 
        } catch (Exception e) { 
            result = ""; 
        return result;