-
Notifications
You must be signed in to change notification settings - Fork 0
/
delivePy_Server.py
73 lines (56 loc) · 1.21 KB
/
delivePy_Server.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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import os
import socket
def conectar(s):
con, addr = s.accept()
print(addr, "se conecto")
return con
def menu():
cont = 1
dirs = []
print("\nElegir archivos:\n")
for e in os.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]
return filename
def enviar(con, filename):
con.send(filename.encode())
file = open(filename,'rb')
while True:
strng = file.readline(512)
if not strng:
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")
'''
def cerrar(con, s):
con.close()
s.close()
def main():
s = socket.socket()
s.bind((socket.gethostname(), 6333))
s.listen()
print("servidor esperando --> {}".format(socket.gethostbyname(socket.gethostname())))
con = conectar(s)
try:
while True:
enviar(con, menu())
except :
pass
cerrar(con, s)
if __name__=='__main__':
main()