Import user from Win FTP 2.x to Wing FTP 4.x

You can share your Lua Scripts with everybody here.

Import user from Win FTP 2.x to Wing FTP 4.x

Postby FTP » Thu May 06, 2010 1:20 pm

-- Description: import users from old Win FTP 2.x to Wing FTP 4.x
-- To execute this lua script, just type a command like "dofile('c:/importuser.lua')" on the Web Admin's Console.
-- Author: Luke
-- Date: 2010-05-05

Code: Select all
require("LuaXML")

function decryption(src)
   local strResult = ""
   local nLength = string.len(src)

   for i=1,nLength do
      local ch = string.char(string.byte(src,i) - nLength - i+1)
      strResult = strResult..ch
   end

   return UnScramble(strResult)
end

function UnScramble(src)
   local strResult = src
   local nEven = 1
   local nOdd = 1
   local nLength = string.len(strResult)
   local strEven = string.sub(strResult, 1, (nLength/2) )
   local strOdd = string.sub(strResult, ((nLength+1)/2), nLength)

   strResult = ""
   for i=1,nLength do
      if (i % 2) == 1 then
         strResult = strResult..string.char(string.byte(strOdd,nOdd))
         nOdd = nOdd + 1
      else
         strResult = strResult..string.char(string.byte(strEven,nEven))
         nEven = nEven + 1
      end
   end

   return strResult
end



local domain = "DomainName"         -- Your domain name
local old_userfile = "c:/users.xml"      -- Old user data filename

local tab = xml.load(old_userfile)

local unum = 1
while tab[unum] ~= nil do
    local dnum = 0

   local username = (tab[unum][1][1])         --username
   local password = ""
   if tab[unum][2][1] ~= nil then
      password = (decryption(tab[unum][2][1]))
   end
   local enable_pass = tonumber(tab[unum][49][1])   --enable password?
   local enable_account = tonumber(tab[unum][15][1])   --enable account?
   if enable_account == 1 then enable_account = 0 else enable_account = 1 end

   c_AddUser(domain,username, md5(password), 63, enable_pass, enable_account)

   while tab[unum][53+dnum] ~= nil do
      local dirpath = (tab[unum][53+dnum][1][1])   --Dir Path
      if dirpath ~= nil then
         dirpath = string.gsub(dirpath,"\\","/")
      end
      local alias = (tab[unum][53+dnum][2][1])      --Alias
      if alias ~= nil then
         alias = string.gsub(alias,"\\","/")
      end
      local fread = (tab[unum][53+dnum][3][1])      --File_Read
      if fread == "1" then fread = true else fread = false end
      local fwrite = (tab[unum][53+dnum][4][1])   --File_Write
      if fwrite == "1" then fwrite = true else fwrite = false end
      local fappend = (tab[unum][53+dnum][5][1])   --File_Append
      if fappend == "1" then fappend = true else fappend = false end
      local fdelete = (tab[unum][53+dnum][6][1])   --File_Delete
      if fdelete == "1" then fdelete = true else fdelete = false end
      local frename = (tab[unum][53+dnum][7][1])   --Directory_Rename
      if frename == "1" then frename = true else frename = false end
      local ishome = (tab[unum][53+dnum][8][1])   --Home_Dir
      if ishome == "1" then ishome = true else ishome = false end
      local dlist = (tab[unum][53+dnum][9][1])   --Directory_List
      if dlist == "1" then dlist = true else dlist = false end
      local dmake = (tab[unum][53+dnum][10][1])   --Directory_Make
      if dmake == "1" then dmake = true else dmake = false end
      local ddelete = (tab[unum][53+dnum][11][1])   --Directory_Delete
      if ddelete == "1" then ddelete = true else ddelete = false end

      if ishome == true then alias = "/" end

      c_AddUserDirectory(domain, username, dirpath, alias, ishome, fread, fwrite, fappend, fdelete, dlist, dmake, ddelete, frename)
      dnum = dnum + 1
   end

   unum = unum + 1
   print("Import user '"..username.."' successfully\n")
end


just save the above scripts to a text file "c:/importuser.lua", then execute it on the web admin's console.

Image



Here we used a xml parser lib, you must download it then unzip it into the working directory of Wing FTP Server.
http://www.wftpserver.com/bbsres/xmlparser.zip

And you can also download this lua script here: http://www.wftpserver.com/bbsres/importuser.lua
FTP
Site Admin
 
posts 1200
 
joined Tue Sep 29, 2009 6:09 am

Return to Lua scripts

Who is online

Users browsing this forum: No registered users and 1 guest