-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcloud_client
More file actions
103 lines (90 loc) · 2.22 KB
/
Copy pathcloud_client
File metadata and controls
103 lines (90 loc) · 2.22 KB
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
100
101
102
103
--api for use of the client's cloud made by oedze
hostID = 4381
encryptFile = "/.cloudDir/encrypt"
os.unloadAPI(encryptFile)
os.loadAPI(encryptFile)
function clear()
term.clear()
term.setCursorPos(1,1)
end
function noHost()
clear()
error("Sorry, but your host didnt respond, try again later.")
end
function login(user, pass)
encPass = encrypt.encrypt(pass, "123cloudSERVICEpassword321")
rednet.send(hostID, "cloudLogin")
print("sended request")
id , msg = rednet.receive(3)
print("received message")
print(msg)
if id == hostID and msg == "sendUser" then
print("message is sendUser")
rednet.send(hostID, user)
print("sended username")
id, msg = rednet.receive(0.5)
if id == hostID and msg == "sendPass" then
print("received sendPass")
rednet.send(hostID, encPass)
print("sended password")
id, status = rednet.receive(2)
print("received status")
if status ~= nil and id == hostID then
print(status)
return status
else
return "no host"
end
else
return "no host"
end
else
print(id)
return "no host"
end
end
function upload(filePath)
rednet.send(hostID, "cloudUpload")
id, msg = rednet.receive(0.5)
if id == hostID and msg == "sendFileName" then
rednet.send(hostID, fs.getName(filePath))
id, msg = rednet.receive(0.5)
if id == hostID and msg == "sendFileData" then
file = fs.open(filePath, "r")
userFileData = file.readAll()
file.close()
rednet.send(hostID, userFileData)
id, status = rednet.receive(2)
return status
else
return "no Host"
end
elseif id == hostID and msg == "no startup" then
return "no startup"
else
return "no Host"
end
end
function download(fileName )
rednet.send(hostID, "cloudDownload")
id, msg = rednet.receive(0.5)
if id == hostID and msg == "sendFileName" then
rednet.send(hostID, fileName)
id, fileData = rednet.receive(5)
if id == hostID and fileData == "not exists" then
return "not exists"
elseif id == hostID and fileData == "noLogin" then
return "noLogin"
elseif id == hostID and fileData ~= nil then
file = fs.open(fileName, "a")
file.write(fileData)
file.close()
rednet.send(hostID, "completed")
return "done"
else
return "no Host"
end
else
return "no Host"
end
end