-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtest_daemon.py
executable file
·81 lines (61 loc) · 1.59 KB
/
test_daemon.py
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
#!/bin/env python3
# connect to daemon and push incoming file
# connect to daemon and get outbound
link_addr = "2:5097/31"
encoding = "utf-8"
import socket
import os
from socketutil import *
try:
os.mkdir("test")
except:
pass
if not os.path.isdir("test"):
print ("please make dir test")
exit()
s = socket.socket(socket.AF_INET)
import ftnconfig
import ftnaccess
db=ftnconfig.connectdb()
link_id = ftnconfig.find_link(db, link_addr)
my_id, password = ftnaccess.link_password(db, link_id, forrobots=False)
print (link_addr, my_id, password)
do_send = False
s.connect(("127.0.0.1", 24555))
try:
print(readline(s))
s.send(b"ADDRESS "+link_addr.encode(encoding)+b"\n")
s.send(b"PASSWORD "+password.encode(encoding)+b"\n")
if do_send:
s.send(b"FILENAME test1.dat\n")
s.send(b"BINARY 100\n")
s.send(b"*"*100)
print(readline(s))
s.send(b"FILENAME test2.dat\n")
s.send(b"BINARY 300\n")
s.send(b"*"*300)
print(readline(s))
s.send(b"GET ALL\n")
while True:
l = readline(s).decode("utf-8")
print("recv:",repr(l))
if l.startswith("FILENAME"):
fn=l[9:]
print("filename:",fn)
f=open("test/"+fn, "wb")
elif l.startswith("BINARY"):
fl=int(l[7:])
print("length:",fl)
for d in readdata(s, fl):
f.write(d)
f.close()
input("commit - if you do it, messages will be marked as send (Ctrl-C to abort)")
s.send(("DONE "+fn+"\n").encode("utf-8"))
elif l=="QUEUE EMPTY":
print ("queue empty")
break
else:
print("unknown sentence")
s.send(b"END SESSION\n")
finally:
s.close()