-- --DCFTP 1.00 -- --by Mutor The Ugly --Connect to FTP servers thru DC hub -- --Features -- *Upload text string or local file to FTP server -- *Download files or diectory listing with option to save as local file -- -- ***Supports ASCII file transfer only -- ***Requires LuaSocket FTP module ftp.lua -- You can download that here: -- http://www.tecgraf.puc-rio.br/luasocket/old/luasocket-1.1/luasocket-1.1.zip -- Downlad and extract ftp.lua to your Ptokax/scripts directory -- -- For more on this version of LuaSocket visit: --http://www.tecgraf.puc-rio.br/luasocket/old/luasocket-1.1/manual.html -- --User Settings------------------------------------------------------------------------------------- Cmd1 = "+dl" --Download command Cmd2 = "+ul" --Upload command Cmd3 = "+save" --Toggle saving download as file locally Save2File = "yes" --Save to text file 'yes/no' Bot = frmHub:GetHubBotName() --Name for bot, if you change this use RegBot in function Main() --End User Settings---------------------------------------------------------------------------------- assert(dofile("ftp.lua"), "ftp.lua is not found") --This file is required see link in notes above --Add other binary file types here if you need Binary = {".exe",".bin",".iso",".img",".vob",".gif",".jpg",".jpeg",".bmp",".tif",".tiff",".avi",".mpg",".mpeg",".ogg",".mp3", ".m2v",".cgi",".zip",".rar",".r01",".ace",".avi",".doc",".exe",".gz ",".hqx",".jar",".jpeg",".jpg",".mov",".mpg",".pdf",".png", ".ppt",".sit",".swf",".tar",".tgz",".xbm",".xls",".zip"} function Main() --frmHub:RegBot(Bot) -- Uncomment if you dont use Px main bot end function DataArrival(user, data) if strsub(data,1,1) == "<" then data = strsub(data,1,strlen(data)-1) local s,e,cmd = strfind(data, "^%b<>%s+(%S+)") if (cmd == Cmd1) and user.bOperator then local s,e,url = strfind(data, "^%b<>%s+%S+%s+(%S+)$") xurl = gsub(url,"%:","-") xurl = gsub(xurl,"%/","-") if not strfind(url, "(%w+%.[^%.%/]+%.%a+)") then local dsp1 dsp1 = "\r\n\t=-=<>=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-=-=<>=-=\r\n" dsp1 = dsp1.."\t Malformed URL, check your spelling\r\n" dsp1 = dsp1.."\t "..url.."\r\n\r\n" dsp1 = dsp1.."\t=-=<>=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-=-=<>=-=\r\n" dsp1 = dsp1.."\t Command Syntax:\r\n" dsp1 = dsp1.."\t "..Cmd1.." ftp://:@\r\n\r\n" dsp1 = dsp1.."\t username and password required if not anonymous server access\r\n" dsp1 = dsp1.."\t Port required if not 21, path & filename optional.\r\n" dsp1 = dsp1.."\t If filename not provided,result will be directory listing.\r\n" dsp1 = dsp1.."\t=-=<>=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-=-=<>=-=\r\n" user:SendData(Bot,dsp1) return 1 else user:SendData(Bot, "Connecting to FTP, please wait for response...\r\n\r\n") f, e = ftp_get(url,a) end if not f then user:SendData(Bot,"\r\n\tBad URL or server is offline\r\n\t"..url.."\r\n\r\n") return 1 else if Save2File == "yes" then filename = "" local _,_,localfile = strfind(data, "%b<>%s+%S+%s+.*%/(%S+%.%w%w%w)$") if localfile == nil then filename = xurl..".txt" else local dsp2 dsp2 = "\r\n\t=-=<>=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-=-=<>=-=\r\n" dsp2 = dsp2.."\t\t Binary file type detected!\r\n" dsp2 = dsp2.."\t=-=<>=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-=-=<>=-=\r\n" dsp2 = dsp2.."\t Sorry, "..user.sName..", [ "..localfile.." ] is a binary file type.\r\n" dsp2 = dsp2.."\t As the intended use is display in Direct Connect \r\n" dsp2 = dsp2.."\t clients, binary files are not supported by this script.\r\n" dsp2 = dsp2.."\t=-=<>=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-=-=<>=-=\r\n" for i,v in Binary do if ( strfind(localfile, v)) then user:SendData(Bot,dsp2) return 1 end end filename = localfile end local handle = openfile(filename,"w") write(handle,f) closefile(handle) else filename = "[ Disabled ]" end f = gsub(f,"\n","\r\n\t\t") local dsp3 dsp3 = "\r\n\t=-=<>=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-=-=<>=-=\r\n" dsp3 = dsp3.."\t Results From: "..url.."\r\n" dsp3 = dsp3.."\t Saving to local file - "..filename.."\r\n" dsp3 = dsp3.."\t=-=<>=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-=-=<>=-=\r\n" dsp3 = dsp3.."\t\t "..f.."\r\n" dsp3 = dsp3.."\t=-=<>=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-=-=<>=-=\r\n" dsp3 = dsp3.."\t Server Response:\r\n" dsp3 = dsp3.."\t [ "..e.." ]\r\n" dsp3 = dsp3.."\t=-=<>=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-=-=<>=-=\r\n" user:SendData(Bot,dsp3) f = "" filename = "" url ="" return 1 end elseif (cmd == Cmd2) and user.bOperator then local dsp4 dsp4 = "\r\n\t=-=<>=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-=-=<>=-=\r\n" dsp4 = dsp4.."\t Malformed URL, check your spelling\r\n" dsp4 = dsp4.."\t Syntax = ftp:// \r\n" dsp4 = dsp4.."\t Port required if not 21, path optional.\r\n" dsp4 = dsp4.."\t=-=<>=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-=-=<>=-=\r\n" local s,e,url = strfind(data, "^%b<>%s+%S+%s+(%S+)") xurl = gsub(url,"%bf@","") fname = gsub(xurl,"(.+%d+)%/","") if not strfind(url, "(%w+%.[^%.%/]+%.%a+)") then user:SendData(Bot,dsp4) return 1 else local s,e,filetxt = strfind(data, "^%b<>%s+%S+%s+%S+%s+(.+)$") if not filetxt then user:SendData(Bot,dsp4) return 1 else local s,e,localfile = strfind(data, "^%b<>%s+%S+%s+%S+%s+(%S+%.%w%w%w)$") if localfile then user:SendData(Bot,"Sending Local File") local handle = openfile(localfile,"r") local sdata = "" if handle then sdata = read(handle,"*a") sdata = gsub(sdata,"\n","\r\n") closefile(handle) end user:SendData(Bot,"Connecting to "..xurl..", Uploading [ "..localfile.." ] please wait for response...\r\n\r\n") e = ftp_put(url,sdata) handle = "" sdata = "" if e ~= nil then user:SendData(Bot,"Server returned error: "..e.." -> "..fname) else user:SendData(Bot,"\r\n\r\nText: "..filetxt.."\r\nUploaded to: "..url.."\r\n") end else user:SendData(Bot,"Connecting to "..xurl..", please wait for response...\r\n\r\n") e = ftp_put(url,filetxt) if e ~= nil then user:SendData(Bot,"Server returned error: "..e.." -> "..fname.."\r\n\r\n") else user:SendData(Bot,"\r\n\r\nText: "..filetxt.."\r\nUploaded to: "..url.."\r\n\r\n") end end end return 1 end elseif (cmd == Cmd3) and user.bOperator then if Save2File == "no" then Save2File = "yes" user:SendData(Bot,"Saving download to file = [ON]") return 1 elseif Save2File == "yes" then Save2File = "no" user:SendData(Bot,"Saving download to file = [OFF]") return 1 end end end end