How to send commands to the console interface on Wing FTP Se

Please post here if you have problems in using Wing FTP Server.
Post Reply
mellul
Posts: 77
Joined: Mon Nov 16, 2009 2:00 pm

How to send commands to the console interface on Wing FTP Se

Post by mellul »

Hi all,

I am new to wing FTP server and I have just figured out how to add a user through the console (LUA format).What I would like to do is write a script that calls the console of Wing FTP server and writes the command to create a user.

Is this possible? Can someone give me some ideas on how to do this? What scripting can you use? Is it possible to use .asp or maybe html or some other scripting/programming language?

The Wing FTP I have donwloaded is version 3.1.2 and will be running on windows 2003 server.

Thanks in advance.

Maria
FTP
Site Admin
Posts: 2072
Joined: Tue Sep 29, 2009 6:09 am

Re: How to send commands to the console interface on Wing FTP Se

Post by FTP »

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;
}
}
mellul
Posts: 77
Joined: Mon Nov 16, 2009 2:00 pm

Re: How to send commands to the console interface on Wing FTP Se

Post by mellul »

Hi,

Firstly I would like to thankyou for your reply. It has been a great help.

I have been looking at the vbscript/asp. I have been trying to test it out as an asp by adding it as a web page to IIS on the same server and running it from another PC through the web page set up.

Please forgive me as I do not have much experience using asp. What I am understanding is that it the script calls the internet explorer and signs in to the admin_login from there (the set xmlHttp line and sets the url on the next line - strUrl). It then enters the account name and password - strUrlParam.

May I ask what the 'cmd=' does?

The strLuaScript then writes to the command line of the wing ftp in Lua - to make things simpler I have replaced this with "c_DeleteUser('test', 'test')" so I can try and delete a user with username test and password test.

I have seen the output of the line xmlHttp.Open "Get" etc. It looks like the script writes all the information in one line and puts it in the address bar (after changing to ASCII).

Am I correct in saying this please? Is there maybe another way I should be running the scripts and not through IIS?

Just to confirm, I am using Wing FTP 3.1.2.

Thanks once again
FTP
Site Admin
Posts: 2072
Joined: Tue Sep 29, 2009 6:09 am

Re: How to send commands to the console interface on Wing FTP Se

Post by FTP »

Hi,

The parameter "cmd" just means the lua scirpts you want to execute.
This function likes some webservice function, you can call it through any way which using http protocol.
mellul
Posts: 77
Joined: Mon Nov 16, 2009 2:00 pm

Re: How to send commands to the console interface on Wing FTP Se

Post by mellul »

Thankyou. I have successfully made the code work :)
Post Reply