Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update env.sh #10

Open
wants to merge 42 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
12cf7d4
Update env.sh
Javi111003 Dec 18, 2024
9c56606
Merge branch 'matcom:main' into main
Javi111003 Jan 23, 2025
b3f1269
feat: Implemented initial server and client and added gitignore
Javi111003 Jan 23, 2025
e617430
doc: Added text file with usual commands on RFC959
Javi111003 Jan 23, 2025
3b06e01
Merge branch 'matcom:main' into main
Javi111003 Jan 27, 2025
b48bf99
Create CODEOWNERS
Javi111003 Jan 27, 2025
824cbb3
feat:Added the logic of the commands in the client and some in the se…
CyberKen10 Jan 27, 2025
16c629f
feat run.sh
Jan 27, 2025
61ec855
fix mock
Jan 27, 2025
1fa6527
fix mock
Jan 27, 2025
e080bad
fix throw error
Jan 28, 2025
f6762b7
fix throw with sys
Jan 28, 2025
515480f
Update tests.py
chriss8g Jan 28, 2025
8cbccfc
check the execution of the last command for exit status 1
rmarticedeno Jan 28, 2025
f696172
fix parse json
Jan 29, 2025
f06ea61
add ftp server and tester
marians002 Jan 2, 2025
f10e3db
remove unnecessary files
rmarticedeno Jan 28, 2025
24e9b8e
test files
rmarticedeno Jan 28, 2025
ba55a81
improve ftp tests
rmarticedeno Jan 29, 2025
5a66954
Add readme, update run.sh
marians002 Jan 7, 2025
59a62ee
solve port mismatch
rmarticedeno Jan 29, 2025
bd52509
fix variable typo
rmarticedeno Jan 29, 2025
4bd63e9
another typo
rmarticedeno Jan 29, 2025
f72477f
revert http change
rmarticedeno Jan 29, 2025
82ccce1
clean unused variable
rmarticedeno Jan 29, 2025
aa85c03
get cwd
rmarticedeno Jan 29, 2025
70b5aaa
list folder files
rmarticedeno Jan 29, 2025
c912d3e
give execution permissions to run.sh file
rmarticedeno Jan 29, 2025
520be0d
use list versions of run
rmarticedeno Jan 29, 2025
8c52160
run.sh as executable
rmarticedeno Jan 29, 2025
3546266
use stdout
rmarticedeno Jan 29, 2025
b92641a
invert order of execution
rmarticedeno Jan 29, 2025
925ee2c
Colored output
rmarticedeno Jan 29, 2025
bb68365
fix tests.py http
Jan 29, 2025
35746d2
delete client.py http
Jan 29, 2025
5c0eb1a
feat server
Dec 14, 2024
c344173
fix smtp server
Jan 29, 2025
9db6d81
fix tests smtp
Jan 29, 2025
1609d57
irc tests
rmarticedeno Jan 30, 2025
de6ca44
Update readme
rmarticedeno Jan 30, 2025
11bb12b
update ftp tests
rmarticedeno Jan 30, 2025
0bb40be
feat:Added the logic of the commands in the client and some in the se…
CyberKen10 Jan 27, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# CODEOWNERS
/FTP/ @Javi111003
42 changes: 42 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Ignorar PyCharm
.idea/

# Archivos de compilación de Python
__pycache__/
*.py[cod]
*$py.class

# Entorno virtual
venv/

# Archivos de logs
*.log

# Archivos temporales
*.tmp
*.swp
*.bak
*.old

# Configuración local de editores
*.vscode/

# Pruebas y cobertura
htmlcov/
*.cover
.coverage
*.coverage.*
.cache
nosetests.xml
coverage.xml

# Bases de datos y archivos grandes
*.sqlite3
*.csv

# Variables de entorno
.env

# Carpeta de descargas FTP
Downloads/
FTP/Downloads/
174 changes: 174 additions & 0 deletions FTP/client.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,174 @@
import socket
import os
from pathlib import Path

class FTPClient:
def __init__(self, host='127.0.0.1', port=21):
self.host = host
self.port = port
self.commands = {}
self._register_commands()
self.downloads_folder = str(Path.cwd() / "Downloads") # Carpeta local Downloads
# Crear la carpeta si no existe
os.makedirs(self.downloads_folder, exist_ok=True)
print(f"Carpeta de descargas: {self.downloads_folder}")

def _register_commands(self):
# Registro de comandos con sus descripciones
self.add_command("USER", "Especifica el usuario")
self.add_command("PASS", "Especifica la contraseña")
self.add_command("PWD", "Muestra el directorio actual")
self.add_command("CWD", "Cambia el directorio de trabajo")
self.add_command("LIST", "Lista archivos y directorios")
self.add_command("MKD", "Crea un directorio")
self.add_command("RMD", "Elimina un directorio")
self.add_command("DELE", "Elimina un archivo")
self.add_command("RNFR", "Especifica el archivo a renombrar")
self.add_command("RNTO", "Especifica el nuevo nombre")
self.add_command("QUIT", "Cierra la conexión")
self.add_command("HELP", "Muestra la ayuda")
self.add_command("SYST", "Muestra información del sistema")
self.add_command("NOOP", "No realiza ninguna operación")
self.add_command("ACCT", "Especifica la cuenta del usuario")
self.add_command("SMNT", "Monta una estructura de sistema de archivos")
self.add_command("REIN", "Reinicia la conexión")
self.add_command("PORT", "Especifica dirección y puerto para conexión")
self.add_command("PASV", "Entra en modo pasivo")
self.add_command("TYPE", "Establece el tipo de transferencia")
self.add_command("STRU", "Establece la estructura de archivo")
self.add_command("MODE", "Establece el modo de transferencia")
self.add_command("RETR", "Recupera un archivo")
self.add_command("STOR", "Almacena un archivo")
self.add_command("STOU", "Almacena un archivo con nombre único")
self.add_command("APPE", "Añade datos a un archivo")
self.add_command("ALLO", "Reserva espacio")
self.add_command("REST", "Reinicia transferencia desde punto")
self.add_command("ABOR", "Aborta operación en progreso")
self.add_command("SITE", "Comandos específicos del sitio")
self.add_command("STAT", "Retorna estado actual")
self.add_command("NLST", "Lista nombres de archivos")

def add_command(self, cmd_name, description):
"""Añade un nuevo comando al cliente"""
self.commands[cmd_name] = description

def send_command(self, sock, command, *args):
full_command = f"{command} {' '.join(args)}".strip()
sock.send(f"{full_command}\r\n".encode())
return sock.recv(1024).decode()

def send_file(self, sock, filename):
"""Envía un archivo al servidor"""
try:
with open(filename, 'rb') as f:
data = f.read()
sock.send(data)
return True
except:
return False

def receive_file(self, sock, filename):
"""Recibe un archivo del servidor en la carpeta Downloads local"""
try:
# Construir la ruta completa en la carpeta Downloads local
download_path = os.path.join(self.downloads_folder, filename)
with open(download_path, 'wb') as f:
while True:
data = sock.recv(1024)
if not data or b"226" in data: # Detectar fin de transferencia
break
f.write(data)
print(f"Archivo guardado en: {download_path}")
return True
except Exception as e:
print(f"Error al recibir archivo: {e}")
return False

def start(self):
client_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
try:
client_socket.connect((self.host, self.port))
print(client_socket.recv(1024).decode())

while True:
try:
command = input("FTP> ").strip().split()
if not command:
continue

cmd = command[0].upper()
args = command[1:] if len(command) > 1 else []

if cmd == "HELP":
if args:
cmd_help = args[0].upper()
if cmd_help in self.commands:
print(f"{cmd_help}: {self.commands[cmd_help]}")
else:
print(f"Comando '{cmd_help}' no reconocido")
else:
print("\nComandos disponibles:")
for cmd_name, desc in sorted(self.commands.items()):
print(f"{cmd_name}: {desc}")
continue

if cmd in self.commands:
# Manejo especial para comandos de transferencia de archivos
if cmd in ["STOR", "RETR", "APPE"]:
if len(args) < 1:
print(f"Uso: {cmd} <filename>")
continue

filename = args[0]
if cmd == "STOR":
if os.path.exists(filename):
response = self.send_command(client_socket, cmd, filename)
print(response)
if "150" in response:
if self.send_file(client_socket, filename):
print("Archivo enviado exitosamente")
else:
print("Error al enviar archivo")
else:
print("Archivo no encontrado")

elif cmd == "RETR":
response = self.send_command(client_socket, cmd, filename)
print(response)
if "150" in response:
if self.receive_file(client_socket, filename):
print("Archivo recibido exitosamente")
else:
print("Error al recibir archivo")

elif cmd == "APPE":
if os.path.exists(filename):
response = self.send_command(client_socket, cmd, filename)
print(response)
if "150" in response:
if self.send_file(client_socket, filename):
print("Archivo anexado exitosamente")
else:
print("Error al anexar archivo")
else:
print("Archivo no encontrado")

else:
response = self.send_command(client_socket, cmd, *args)
print(response)
if cmd == "QUIT":
break
else:
print("Comando no reconocido")

except Exception as e:
print(f"Error: {e}")

except Exception as e:
print(f"Error de conexión: {e}")
finally:
client_socket.close()

if __name__ == "__main__":
client = FTPClient()
client.start()
Loading
Loading