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

Commit 7c5b7e2

Browse files
committed
arreglado algunos comandos en el servidor
1 parent 880d869 commit 7c5b7e2

File tree

4 files changed

+173
-199
lines changed

4 files changed

+173
-199
lines changed

proyecto/Downloads/comandos.txt

Lines changed: 0 additions & 129 deletions
This file was deleted.

proyecto/full_client.py

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def send_command(self, sock, command, *args):
5353

5454
response = ""
5555
while True:
56-
data = sock.recv(1024).decode()
56+
data = sock.recv(8192).decode()
5757
if not data: # Si no hay más datos, salir del bucle
5858
break
5959
response += data
@@ -69,7 +69,7 @@ def send_stor_command(self, sock, data_sock, command, *args):
6969

7070
response = ""
7171
while True:
72-
data = sock.recv(1024).decode()
72+
data = sock.recv(8192).decode()
7373
if not data: # Si no hay más datos, salir del bucle
7474
break
7575
if "150" in data:
@@ -91,7 +91,7 @@ def send_command_multiresponse(self, sock, command, *args):
9191

9292
response = ""
9393
while True:
94-
data = sock.recv(1024).decode()
94+
data = sock.recv(8192).decode()
9595
if not data: # Si no hay más datos, salir del bucle
9696
break
9797
response += data
@@ -107,7 +107,7 @@ def send_file(self, sock, filename):
107107
print(filename)
108108
with open(filename, 'rb') as f:
109109
while True:
110-
data = f.read(4096)
110+
data = f.read()
111111
print(data)
112112
if not data:
113113
break
@@ -125,8 +125,8 @@ def receive_file(self, sock, filename):
125125
download_path = os.path.join(self.downloads_folder, filename)
126126
with open(download_path, 'wb') as f:
127127
while True:
128-
data = sock.recv(1024)
129-
if not data or b"226" in data: # Detectar fin de transferencia
128+
data = sock.recv(8192)
129+
if not data: # Detectar fin de transferencia
130130
break
131131
f.write(data)
132132
print(f"Archivo guardado en: {download_path}")
@@ -164,7 +164,7 @@ def start(self):
164164
client_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
165165
try:
166166
client_socket.connect((self.host, self.port))
167-
print(client_socket.recv(1024).decode())
167+
print(client_socket.recv(8192).decode())
168168

169169
while True:
170170
try:
@@ -190,7 +190,7 @@ def start(self):
190190

191191
if cmd in self.commands_help:
192192
# Manejo especial para comandos que requieren modo pasivo
193-
if cmd in ["LIST", "RETR", "STOR", "APPE"]:
193+
if cmd in ["LIST", "RETR", "STOR", "APPE", "NLST"]:
194194
# Enviar el comando PASV y obtener la respuesta
195195
response = self.send_command(client_socket, "PASV")
196196
print(response)
@@ -214,11 +214,12 @@ def start(self):
214214
data_sock.connect((ip, port))
215215

216216
try:
217-
if cmd == "LIST":
218-
response = self.send_command_multiresponse(client_socket, "LIST")
217+
if cmd == "LIST" or cmd == "NLST":
218+
path = args[0] if args else '.'
219+
response = self.send_command_multiresponse(client_socket, cmd, path)
219220
print(response)
220221
if "150" in response:
221-
data = data_sock.recv(4096).decode()
222+
data = data_sock.recv(8192).decode()
222223
print(data)
223224
data_sock.close() # Cerrar el socket de datos
224225

@@ -246,18 +247,12 @@ def start(self):
246247

247248
elif cmd == "APPE":
248249
if os.path.exists(filename):
249-
response = self.send_command_multiresponse(client_socket, "APPE", filename)
250+
response = self.send_stor_command(client_socket, data_sock, "APPE", filename)
250251
print(response)
251-
if "150" in response:
252-
if self.send_file(data_sock, filename):
253-
print("Archivo anexado exitosamente")
254-
else:
255-
print("Error al anexar archivo")
256252
else:
257253
print("Archivo no encontrado")
258254
finally:
259-
data_sock.close() # Cerrar el socket de datos
260-
255+
data_sock.close() # Cerrar el socket de datos
261256
else:
262257
# Comandos que no requieren modo pasivo
263258
response = self.send_command(client_socket, cmd, *args)

proyecto/new.txt

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)