Wing FTP Server also provides an useful
REST web service for administration, and you can call it for executing lua script in any external programming languages.The RESTful web service URL may look like this:
http://127.0.0.1:5466/admin_webservice. ... &cmd=xxxxx
There are three URL parameters in the above string, the first parameter "admin" means the administrator's username, the second parameter "pass" means the administrator's password, the third parameter "cmd" means the lua script with urlecoded.If the web service call failed, it will return a string start with "[ERROR RESULT]".
Here we will present an example in some programming languages, this example is very simple, just for calculating the sum of all the domain's online session number.
PHP example:
$strUrl = "
http://127.0.0.1:9999/admin_webservice.html";
$strUrlParam = "?admin=demo&pass=demo123&cmd=";
$strLuaScript = <<<EOT
local nSessionCnt = 0
for _,domain in pairs(c_GetDomainList()) do
nSessionCnt = nSessionCnt + c_GetSessionCount(domain)
end
print(nSessionCnt)
EOT;
$strResult = file_get_contents($strUrl.$strUrlParam.rawurlencode($strLuaScript));
VB script/ASP example:
Set xmlHttp = CreateObject("MSXML2.ServerXMLHTTP")
strUrl = "
http://127.0.0.1:9999/admin_webservice.html"
strUrlParam = "?admin=demo&pass=demo123&cmd="
strLuaScript = "local nSessionCnt = 0 "_
&"for _,domain in pairs(c_GetDomainList()) do "_
&" nSessionCnt = nSessionCnt + c_GetSessionCount(domain) "_
&"end "_
&"print(nSessionCnt)"
xmlHttp.open "GET", strUrl&strUrlParam&URLEncode(strLuaScript), False
xmlHttp.send
strResult = xmlHttp.responseText
Function URLEncode(strInput)
For i = 1 To Len(strInput)
intAscii = Asc(Mid(strInput, i, 1))
If ((intAscii < 58) And (intAscii > 47)) Or ((intAscii < 91) And (intAscii > 64)) Or ((intAscii < 123) And (intAscii > 96)) Then
strOutput = strOutput & Chr(intAscii)
Else
If intAscii < 16 Then
strOutput = strOutput & "%0" & Trim(Hex(intAscii))
Else
strOutput = strOutput & "%" & Trim(Hex(intAscii))
End If
End If
Next
URLEncode = strOutput
End Function
JAVA example:
import java.io.*;
import java.net.*;
class GetUrlContent {
public static void main(String[] args) throws IOException {
String strUrl = "
http://127.0.0.1:9999/admin_webservice.html";
String strUrlParam = "admin=demo&pass=demo123&cmd=";
String strLuaScript = "local nSessionCnt = 0 "+
"for _,domain in pairs(c_GetDomainList()) do "+
" nSessionCnt = nSessionCnt + c_GetSessionCount(domain) "+
"end "+
"print(nSessionCnt)"
String strResult = SendGetRequest(strUrl, strUrlParam+java.net.URLEncoder.encode(strLuaScript));
}
public static String SendGetRequest(String url, String param) {
String result = "";
try {
String urlName = url + "?" + param;
URL U = new URL(urlName);
URLConnection connection = U.openConnection();
connection.connect();
BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
String line;
while ((line = in.readLine()) != null) {
result += line;
}
in.close();
} catch (Exception e) {
result = "";
}
return result;
}
}