@@ -71,7 +71,7 @@ int get_client_ip_port(char *str, char *client_ip, int *client_port){
71
71
x6 = atoi (n6 );
72
72
* client_port = (256 * x5 )+ x6 ;
73
73
74
- printf ("client_ip : %s client_port : %d\n" , client_ip , * client_port );
74
+ printf ("Client's IP : %s Port : %d\n" , client_ip , * client_port );
75
75
return 1 ;
76
76
}
77
77
@@ -80,7 +80,7 @@ int setup_data_connection(int *fd, char *client_ip, int client_port, int server_
80
80
struct sockaddr_in cliaddr , tempaddr ;
81
81
82
82
if ( (* fd = socket (AF_INET , SOCK_STREAM , 0 )) < 0 ){
83
- perror ("socket error" );
83
+ perror ("err: socket error" );
84
84
return -1 ;
85
85
}
86
86
@@ -102,12 +102,12 @@ int setup_data_connection(int *fd, char *client_ip, int client_port, int server_
102
102
cliaddr .sin_family = AF_INET ;
103
103
cliaddr .sin_port = htons (client_port );
104
104
if (inet_pton (AF_INET , client_ip , & cliaddr .sin_addr ) <= 0 ){
105
- perror ("inet_pton error" );
105
+ perror ("err: inet_pton error" );
106
106
return -1 ;
107
107
}
108
108
109
109
if (connect (* fd , (struct sockaddr * ) & cliaddr , sizeof (cliaddr )) < 0 ){
110
- perror ("connect error" );
110
+ perror ("err: connect error" );
111
111
return -1 ;
112
112
}
113
113
@@ -147,21 +147,13 @@ int _ls(int controlfd, int datafd, char *input){
147
147
memset (filelist , '\0' , (int )sizeof (filelist ));
148
148
149
149
if (get_filename (input , filelist ) > 0 ){
150
- printf ( "Filelist Detected\n" );
150
+
151
151
sprintf (str , "ls %s" , filelist );
152
152
printf ("Filelist: %s\n" , filelist );
153
153
rm_lt_spaces (filelist );
154
- //verify that given input is valid
155
- /*struct stat statbuf;
156
- stat(filelist, &statbuf);
157
- if(!(S_ISDIR(statbuf.st_mode))) {
158
- sprintf(sendline, "550 No Such File or Directory\n");
159
- write(controlfd, sendline, strlen(sendline));
160
- return -1;
161
- }*/
162
154
DIR * dir = opendir (filelist );
163
155
if (!dir ){
164
- sprintf (sendline , "550 No Such File or Directory \n" );
156
+ sprintf (sendline , "No such file or directory \n" );
165
157
write (controlfd , sendline , strlen (sendline ));
166
158
return -1 ;
167
159
}else {closedir (dir );}
@@ -170,12 +162,12 @@ int _ls(int controlfd, int datafd, char *input){
170
162
sprintf (str , "ls" );
171
163
}
172
164
173
- // initiate file pointer for popen()
165
+ // initiate file pointer for popen()
174
166
FILE * in ;
175
167
extern FILE * popen ();
176
168
177
169
if (!(in = popen (str , "r" ))) {
178
- sprintf (sendline , "451 Requested action aborted . Local error in processing\n" );
170
+ sprintf (sendline , "Abort action. Local error in processing\n" );
179
171
write (controlfd , sendline , strlen (sendline ));
180
172
return -1 ;
181
173
}
@@ -186,7 +178,7 @@ int _ls(int controlfd, int datafd, char *input){
186
178
memset (sendline , '\0' , (int )sizeof (sendline ));
187
179
}
188
180
189
- sprintf (sendline , "200 Command OK " );
181
+ sprintf (sendline , "status: successful " );
190
182
write (controlfd , sendline , strlen (sendline ));
191
183
pclose (in );
192
184
@@ -210,7 +202,7 @@ int _get(int controlfd, int datafd, char *input){
210
202
}
211
203
}else {
212
204
printf ("Filename Not Detected\n" );
213
- sprintf (sendline , "450 Requested file action not taken.\nFilename Not Detected \n" );
205
+ sprintf (sendline , "Abort action. Local error in processing \n" );
214
206
write (controlfd , sendline , strlen (sendline ));
215
207
return -1 ;
216
208
}
@@ -219,18 +211,17 @@ int _get(int controlfd, int datafd, char *input){
219
211
extern FILE * popen ();
220
212
221
213
if (!(in = popen (str , "r" ))) {
222
- sprintf (sendline , "451 Requested action aborted . Local error in processing\n" );
214
+ sprintf (sendline , "Abort action. Local error in processing\n" );
223
215
write (controlfd , sendline , strlen (sendline ));
224
216
return -1 ;
225
217
}
226
218
227
219
while (fgets (sendline , MAXLINE , in ) != NULL ) {
228
220
write (datafd , sendline , strlen (sendline ));
229
- //printf("%s", sendline);
230
221
memset (sendline , '\0' , (int )sizeof (sendline ));
231
222
}
232
223
233
- sprintf (sendline , "200 Command OK " );
224
+ sprintf (sendline , "status: successful " );
234
225
write (controlfd , sendline , strlen (sendline ));
235
226
pclose (in );
236
227
return 1 ;
0 commit comments