Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Madpondia Inc.
- --A bug with similar coding to IRC will result in chat appearing in console window
- local side='right' -- Rednet side
- local name='test' -- Server name
- wait=5
- if fs.exists('/ftp')==false then
- fs.makeDir('/ftp')
- end
- function split(pString, pPattern)
- local Table = {} -- NOTE: use {n = 0} in Lua-5.0
- local fpat = "(.-)" .. pPattern
- local last_end = 1
- local s, e, cap = pString:find(fpat, 1)
- while s do
- if s ~= 1 or cap ~= "" then
- table.insert(Table,cap)
- end
- last_end = e+1
- s, e, cap = pString:find(fpat, last_end)
- end
- if last_end <= #pString then
- cap = pString:sub(last_end)
- table.insert(Table, cap)
- end
- return Table
- end
- term.clear()
- term.setCursorPos((term.getSize()/2)-13,1)
- print('Iomega Service Listener')
- print('--------------------------------------------------')
- print('Allow 10 seconds for services to start!')
- rednet.open(side)
- while true do
- id,res=rednet.receive(wait)
- if res == nil then
- if wait==5 then
- print('--------------------------------------------------')
- wait=wait+60
- end
- else
- wait=5
- print(id..'->'..res)
- res=split(res,'\:')
- if res[1]=='ftp' and res[2]==name then
- if res[3]=='id' then
- rednet.send(id,'')
- elseif res[3]=='get' then
- fl=''
- fnf='File Not Found'
- if res[4]==nil then
- out=fnf
- else
- fl='/ftp/'..res[4]
- end
- if fs.exists(fl) and fs.isDir(fl)==false then
- file=fs.open(fl,'r')
- out=file.readAll()
- file.close()
- else
- out=fnf
- end
- rednet.send(id,out)
- elseif res[3]=='set' then
- fl=''
- if res[4]==nil then
- rednet.send(id,'INVALID')
- else
- fl='/ftp/'..res[4]
- end
- if fs.exists(fl)==false then
- rednet.send(id,'OK')
- id2,rec=rednet.receive(10)
- if id2==id then
- file=fs.open(fl,'w')
- out=file.write()
- file.close()
- end
- else
- rednet.send(id,'EXISTS')
- end
- elseif res[1]== "ikilltheworld" then --Not Currently working, Useage, Server
- --Control from central console
- --Plan to have a dedicated console, with access methods only usable
- --by certain logins, For the mean TIME, DO NOT TOUCH THIS MODULE
- os.shutdown()
- elseif res[3]=='ls' then
- lst={}
- out=''
- if res[4]==nil then
- lst='/ftp'
- else
- lst='/ftp/'..res[4]
- end
- if fs.exists(lst) and fs.isDir(lst) then
- lst2=fs.list(lst)
- for k,v in ipairs(lst2) do
- if fs.isDir(lst..'/'..v) then
- out=out..'\nD '
- else
- out=out..'\nF '
- end
- out=out..v
- end
- else
- out='\nDirectory does not exist'
- end
- if out=='' then out='\nNo Files Found' end
- if not res[4]==nil then
- out=res[4]..out
- end
- rednet.send(id,'File listing: '..out)
- end
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement