Skip to content
This repository was archived by the owner on Apr 1, 2025. It is now read-only.

Commit b3f1269

Browse files
committed
feat: Implemented initial server and client and added gitignore
1 parent 9c56606 commit b3f1269

File tree

3 files changed

+109
-0
lines changed

3 files changed

+109
-0
lines changed

.gitignore

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# Ignorar PyCharm
2+
.idea/
3+
4+
# Archivos de compilación de Python
5+
__pycache__/
6+
*.py[cod]
7+
*$py.class
8+
9+
# Entorno virtual
10+
venv/
11+
12+
# Archivos de logs
13+
*.log
14+
15+
# Archivos temporales
16+
*.tmp
17+
*.swp
18+
*.bak
19+
*.old
20+
21+
# Configuración local de editores
22+
*.vscode/
23+
24+
# Pruebas y cobertura
25+
htmlcov/
26+
*.cover
27+
.coverage
28+
*.coverage.*
29+
.cache
30+
nosetests.xml
31+
coverage.xml
32+
33+
# Bases de datos y archivos grandes
34+
*.sqlite3
35+
*.csv
36+
37+
# Variables de entorno
38+
.env

FTP/client.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import socket
2+
3+
def start_ftp_client(host='127.0.0.1', port=21):
4+
client_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
5+
client_socket.connect((host, port))
6+
7+
# Recibir saludo del servidor
8+
print(client_socket.recv(1024).decode())
9+
10+
while True:
11+
command = input("FTP> ")
12+
if command.lower() == 'quit':
13+
client_socket.send(b"QUIT\r\n")
14+
break
15+
client_socket.send((command + "\r\n").encode())
16+
response = client_socket.recv(1024).decode()
17+
print(response)
18+
19+
client_socket.close()
20+
21+
if __name__ == "__main__":
22+
start_ftp_client()

FTP/server.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import socket
2+
import os
3+
4+
5+
def start_ftp_server(host='0.0.0.0', port=21):
6+
server_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
7+
server_socket.bind((host, port))
8+
server_socket.listen(5)
9+
print(f"Servidor FTP iniciado en {host}:{port}")
10+
11+
while True:
12+
client_socket, client_address = server_socket.accept()
13+
print(f"Cliente conectado: {client_address}")
14+
handle_client(client_socket)
15+
16+
17+
def handle_client(client_socket):
18+
client_socket.send(b"220 Bienvenido al servidor FTP\r\n")
19+
while True:
20+
try:
21+
command = client_socket.recv(1024).decode().strip()
22+
if not command:
23+
break
24+
25+
print(f"Comando recibido: {command}")
26+
27+
# Procesar comandos FTP básicos
28+
if command.upper().startswith("USER"):
29+
client_socket.send(b"331 Usuario aceptado, se requiere contraseña.\r\n")
30+
elif command.upper().startswith("PASS"):
31+
client_socket.send(b"230 Usuario autenticado con éxito.\r\n")
32+
elif command.upper() == "QUIT":
33+
client_socket.send(b"221 Cerrando conexión.\r\n")
34+
break
35+
elif command.upper() == "LIST":
36+
# Respuesta de ejemplo para LIST
37+
files = "\r\n".join(os.listdir(".")).encode()
38+
client_socket.send(b"150 Listado de directorio:\r\n")
39+
client_socket.send(files + b"\r\n")
40+
client_socket.send(b"226 Listado completado.\r\n")
41+
else:
42+
client_socket.send(b"502 Comando no implementado.\r\n")
43+
except ConnectionResetError:
44+
break
45+
client_socket.close()
46+
47+
48+
if __name__ == "__main__":
49+
start_ftp_server()

0 commit comments

Comments
 (0)