mish
parent
731290b3ad
commit
8b8d5679cf
|
|
@ -0,0 +1,17 @@
|
||||||
|
# Detectar el sistema operativo y
|
||||||
|
|
||||||
|
# ---- Librerías ------
|
||||||
|
import os
|
||||||
|
import platform
|
||||||
|
# ---- Librerías ------
|
||||||
|
|
||||||
|
|
||||||
|
my_os = platform.system()
|
||||||
|
|
||||||
|
def asignar carpeta_guardado(my_os):
|
||||||
|
if my_os = "Linux" or my_os = "Darwin":
|
||||||
|
# download_path = (/home/{USER}/Downloads/)
|
||||||
|
if my_os = "Windows":
|
||||||
|
# download_path = (/home/)
|
||||||
|
return download_path
|
||||||
|
|
||||||
|
|
@ -0,0 +1,107 @@
|
||||||
|
# menu_cliente.py
|
||||||
|
import socket
|
||||||
|
import os
|
||||||
|
import subprocess
|
||||||
|
|
||||||
|
def limpiar_pantalla():
|
||||||
|
"""Limpia la pantalla (funciona en Linux y Mac)"""
|
||||||
|
subprocess.run('clear', shell=True)
|
||||||
|
|
||||||
|
def mostrar_menu():
|
||||||
|
print("🖥️ ENVIADOR DE ARCHIVOS")
|
||||||
|
print("=" * 30)
|
||||||
|
print("1. 📱 Enviar a Linux")
|
||||||
|
print("2. 🍎 Enviar a Mac")
|
||||||
|
print("3. 🪟 Enviar a Windows")
|
||||||
|
print("4. 🚪 Salir")
|
||||||
|
print("=" * 30)
|
||||||
|
|
||||||
|
def obtener_ip(dispositivo):
|
||||||
|
"""Pide la IP según el dispositivo"""
|
||||||
|
ips = {
|
||||||
|
"Linux": "Ej: 192.168.1.100",
|
||||||
|
"Mac": "Ej: 192.168.1.101",
|
||||||
|
"Windows": "Ej: 192.168.1.102"
|
||||||
|
}
|
||||||
|
|
||||||
|
print(f"\n📍 Configurando envío a {dispositivo}")
|
||||||
|
ip = input(f"IP del {dispositivo} ({ips[dispositivo]}): ")
|
||||||
|
return ip
|
||||||
|
|
||||||
|
def enviar_archivo(ruta, ip_servidor):
|
||||||
|
"""Función para enviar archivo (la misma de antes)"""
|
||||||
|
if not os.path.exists(ruta):
|
||||||
|
print("❌ El archivo no existe")
|
||||||
|
input("Presiona Enter para continuar...")
|
||||||
|
return False
|
||||||
|
|
||||||
|
try:
|
||||||
|
client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||||
|
client.connect((ip_servidor, 5000))
|
||||||
|
|
||||||
|
nombre = os.path.basename(ruta)
|
||||||
|
tamaño = os.path.getsize(ruta)
|
||||||
|
|
||||||
|
client.send(f"{nombre}|{tamaño}".encode())
|
||||||
|
|
||||||
|
print(f"📤 Enviando: {nombre}...")
|
||||||
|
with open(ruta, "rb") as f:
|
||||||
|
while True:
|
||||||
|
datos = f.read(4096)
|
||||||
|
if not datos:
|
||||||
|
break
|
||||||
|
client.send(datos)
|
||||||
|
|
||||||
|
respuesta = client.recv(1024).decode()
|
||||||
|
print(f"✅ {respuesta}")
|
||||||
|
client.close()
|
||||||
|
|
||||||
|
input("Presiona Enter para continuar...")
|
||||||
|
return True
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
print(f"❌ Error: No se pudo conectar a {ip_servidor}")
|
||||||
|
input("Presiona Enter para continuar...")
|
||||||
|
return False
|
||||||
|
|
||||||
|
def main():
|
||||||
|
while True:
|
||||||
|
limpiar_pantalla()
|
||||||
|
mostrar_menu()
|
||||||
|
|
||||||
|
opcion = input("\nSelecciona una opción (1-4): ")
|
||||||
|
|
||||||
|
if opcion == "1":
|
||||||
|
limpiar_pantalla()
|
||||||
|
print("🖥️ ENVIAR A LINUX")
|
||||||
|
print("=" * 25)
|
||||||
|
ip = obtener_ip("Linux")
|
||||||
|
archivo = input("📁 Ruta del archivo a enviar: ")
|
||||||
|
enviar_archivo(archivo, ip)
|
||||||
|
|
||||||
|
elif opcion == "2":
|
||||||
|
limpiar_pantalla()
|
||||||
|
print("🍎 ENVIAR A MAC")
|
||||||
|
print("=" * 25)
|
||||||
|
ip = obtener_ip("Mac")
|
||||||
|
archivo = input("📁 Ruta del archivo a enviar: ")
|
||||||
|
enviar_archivo(archivo, ip)
|
||||||
|
|
||||||
|
elif opcion == "3":
|
||||||
|
limpiar_pantalla()
|
||||||
|
print("🪟 ENVIAR A WINDOWS")
|
||||||
|
print("=" * 25)
|
||||||
|
ip = obtener_ip("Windows")
|
||||||
|
archivo = input("📁 Ruta del archivo a enviar: ")
|
||||||
|
enviar_archivo(archivo, ip)
|
||||||
|
|
||||||
|
elif opcion == "4":
|
||||||
|
print("👋 ¡Hasta luego!")
|
||||||
|
break
|
||||||
|
|
||||||
|
else:
|
||||||
|
print("❌ Opción inválida")
|
||||||
|
input("Presiona Enter para continuar...")
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
|
|
@ -0,0 +1,4 @@
|
||||||
|
# Importar librerías y archivos
|
||||||
|
|
||||||
|
import sistema_operativo
|
||||||
|
# import
|
||||||
|
|
@ -0,0 +1,42 @@
|
||||||
|
# servidor_universal.py
|
||||||
|
import socket
|
||||||
|
import os
|
||||||
|
|
||||||
|
if not os.path.exists("recibidos"):
|
||||||
|
os.makedirs("recibidos")
|
||||||
|
|
||||||
|
server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||||
|
server.bind(('0.0.0.0', 5000))
|
||||||
|
server.listen(1)
|
||||||
|
|
||||||
|
print("🖥️ Servidor Universal Escuchando...")
|
||||||
|
print("📍 IPs disponibles:")
|
||||||
|
os.system("hostname -I 2>/dev/null || ipconfig 2>/dev/null")
|
||||||
|
print("🔌 Puerto: 5000")
|
||||||
|
print("=" * 40)
|
||||||
|
|
||||||
|
while True:
|
||||||
|
try:
|
||||||
|
client, addr = server.accept()
|
||||||
|
print(f"📨 Conexión entrante de: {addr}")
|
||||||
|
|
||||||
|
info = client.recv(1024).decode()
|
||||||
|
nombre, tamaño = info.split("|")
|
||||||
|
tamaño = int(tamaño)
|
||||||
|
|
||||||
|
with open(f"recibidos/{nombre}", "wb") as f:
|
||||||
|
recibido = 0
|
||||||
|
while recibido < tamaño:
|
||||||
|
datos = client.recv(4096)
|
||||||
|
f.write(datos)
|
||||||
|
recibido += len(datos)
|
||||||
|
|
||||||
|
print(f"✅ {nombre} recibido correctamente!")
|
||||||
|
client.send("Archivo recibido ✅".encode())
|
||||||
|
client.close()
|
||||||
|
|
||||||
|
except KeyboardInterrupt:
|
||||||
|
print("\n👋 Servidor cerrado")
|
||||||
|
break
|
||||||
|
except Exception as e:
|
||||||
|
print(f"❌ Error: {e}")
|
||||||
Loading…
Reference in New Issue