@@ -53,7 +53,7 @@ def send_command(self, sock, command, *args):
53
53
54
54
response = ""
55
55
while True :
56
- data = sock .recv (1024 ).decode ()
56
+ data = sock .recv (8192 ).decode ()
57
57
if not data : # Si no hay más datos, salir del bucle
58
58
break
59
59
response += data
@@ -69,7 +69,7 @@ def send_stor_command(self, sock, data_sock, command, *args):
69
69
70
70
response = ""
71
71
while True :
72
- data = sock .recv (1024 ).decode ()
72
+ data = sock .recv (8192 ).decode ()
73
73
if not data : # Si no hay más datos, salir del bucle
74
74
break
75
75
if "150" in data :
@@ -91,7 +91,7 @@ def send_command_multiresponse(self, sock, command, *args):
91
91
92
92
response = ""
93
93
while True :
94
- data = sock .recv (1024 ).decode ()
94
+ data = sock .recv (8192 ).decode ()
95
95
if not data : # Si no hay más datos, salir del bucle
96
96
break
97
97
response += data
@@ -107,7 +107,7 @@ def send_file(self, sock, filename):
107
107
print (filename )
108
108
with open (filename , 'rb' ) as f :
109
109
while True :
110
- data = f .read (4096 )
110
+ data = f .read ()
111
111
print (data )
112
112
if not data :
113
113
break
@@ -125,8 +125,8 @@ def receive_file(self, sock, filename):
125
125
download_path = os .path .join (self .downloads_folder , filename )
126
126
with open (download_path , 'wb' ) as f :
127
127
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
130
130
break
131
131
f .write (data )
132
132
print (f"Archivo guardado en: { download_path } " )
@@ -164,7 +164,7 @@ def start(self):
164
164
client_socket = socket .socket (socket .AF_INET , socket .SOCK_STREAM )
165
165
try :
166
166
client_socket .connect ((self .host , self .port ))
167
- print (client_socket .recv (1024 ).decode ())
167
+ print (client_socket .recv (8192 ).decode ())
168
168
169
169
while True :
170
170
try :
@@ -190,7 +190,7 @@ def start(self):
190
190
191
191
if cmd in self .commands_help :
192
192
# 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" ]:
194
194
# Enviar el comando PASV y obtener la respuesta
195
195
response = self .send_command (client_socket , "PASV" )
196
196
print (response )
@@ -214,11 +214,12 @@ def start(self):
214
214
data_sock .connect ((ip , port ))
215
215
216
216
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 )
219
220
print (response )
220
221
if "150" in response :
221
- data = data_sock .recv (4096 ).decode ()
222
+ data = data_sock .recv (8192 ).decode ()
222
223
print (data )
223
224
data_sock .close () # Cerrar el socket de datos
224
225
@@ -246,18 +247,12 @@ def start(self):
246
247
247
248
elif cmd == "APPE" :
248
249
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 )
250
251
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" )
256
252
else :
257
253
print ("Archivo no encontrado" )
258
254
finally :
259
- data_sock .close () # Cerrar el socket de datos
260
-
255
+ data_sock .close () # Cerrar el socket de datos
261
256
else :
262
257
# Comandos que no requieren modo pasivo
263
258
response = self .send_command (client_socket , cmd , * args )
0 commit comments