-
Notifications
You must be signed in to change notification settings - Fork 0
/
client.lua
99 lines (88 loc) · 2.11 KB
/
client.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
-- --
-- Simple Ftp-Client for lua --
-- (C) Alex Kondratenko 2019 --
-- mailto: [email protected] --
-- --
-- io_compatibility = true -- see conio.lua
require "include"
stdconfig = {
welcome = "Welcome to Simple Ftp-Client by _KROL",
clnorm = 0x0F,
clpre = 0x09,
clok = 0x0A,
clinter = 0x0E,
clerr = 0x0C,
help = { colons = 5, width = 10 }
}
command = {}
control = Sock:new()
data = Sock:new()
stat = {
quit = false,
type = "I",
}
local function setaliases()
command.chdir = command.cd;
command.down = command.get;
command.up = command.send;
command.exit = command.quit;
command.ls = command.dir;
command.mkdir = command.md;
command.rm = command.del;
end
local function init()
local d = lfs.readdir("src")
for _, x in ipairs(d) do
local p, f, e = string.splitpath(x)
if e == "lua" then
command[f] = require(p..f)
config[f] = {}
config[f].help = command[f].help
end
end
setaliases()
config.load(stdconfig)
command["help"].init()
oldattr = io.getattr()
end init()
color = { -- Временно (пока config.TODO)
norm = config.clnorm,
pre = config.clpre,
ok = config.clok,
inter = config.clinter,
err = config.clerr,
}
local function main()
io.setattr(config.clnorm)
print(config.welcome)
repeat
io.setattr(color.norm)
s = io.sread("ftp> "):trimspaces()
io.setattr(color.ok)
if s then
local ss = s:sub(2):trimspaces()
if s:sub(1, 1) == '~' then
command["raw"].main(ss)
elseif s:sub(1, 1) == '?' then
command["help"].main(ss)
elseif s:sub(1, 1) == '!' then
command["exec"].main(ss)
else
local i, j = s:find("[^%s]+")
if i then
cmd = s:sub(i, j):lower()
if command[cmd] then
s = s:sub(j+1):trimspaces()
command[cmd].main(s~="" and s or nil)
else
Error_cmd(cmd)
end
end
end
end
until stat.quit
end main()
local function done()
io.setattr(oldattr)
config.save()
end done()