- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdelivePy_Server.py
More file actions
Latest commit
73 lines (56 loc) · 1.21 KB
/
Copy pathdelivePy_Server.py
File metadata and controls
73 lines (56 loc) · 1.21 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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
importos
importsocket
defconectar(s):
con, addr=s.accept()
print(addr, "se conecto")
returncon
defmenu():
cont=1
dirs= []
print("\nElegir archivos:\n")
foreinos.scandir(os.getcwd()):
dirs.append(e.name)
print(" [{}] - {}".format(cont, e.name))
cont+=1
print("\n\t\t\tpress (q) for quit.\n")
eleccion=input("Archivo a enviar --> ")
filename=dirs[int(eleccion)-1]
returnfilename
defenviar(con, filename):
con.send(filename.encode())
file=open(filename,'rb')
whileTrue:
strng=file.readline(512)
ifnotstrng:
break
con.send(strng)
file.close()
print("archivo enviado con exito")
'''
def enviar(con, filename):
con.send(filename.encode())
file = open(filename, 'rb')
fileContent = file.read(1024)
con.send(fileContent)
file.close()
print("archivo enviado con etsito")
'''
defcerrar(con, s):
con.close()
s.close()
defmain():
s=socket.socket()
s.bind((socket.gethostname(), 6333))
s.listen()
print("servidor esperando --> {}".format(socket.gethostbyname(socket.gethostname())))
con=conectar(s)
try:
whileTrue:
enviar(con, menu())
except :
pass
cerrar(con, s)
if__name__=='__main__':
main()