@@ -71,7 +71,7 @@ int get_client_ip_port(char *str, char *client_ip, int *client_port){
7171 x6 = atoi (n6 );
7272 * client_port = (256 * x5 )+ x6 ;
7373
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 );
7575 return 1 ;
7676}
7777
@@ -80,7 +80,7 @@ int setup_data_connection(int *fd, char *client_ip, int client_port, int server_
8080 struct sockaddr_in cliaddr , tempaddr ;
8181
8282 if ( (* fd = socket (AF_INET , SOCK_STREAM , 0 )) < 0 ){
83- perror ("socket error" );
83+ perror ("err: socket error" );
8484 return -1 ;
8585 }
8686
@@ -102,12 +102,12 @@ int setup_data_connection(int *fd, char *client_ip, int client_port, int server_
102102 cliaddr .sin_family = AF_INET ;
103103 cliaddr .sin_port = htons (client_port );
104104 if (inet_pton (AF_INET , client_ip , & cliaddr .sin_addr ) <= 0 ){
105- perror ("inet_pton error" );
105+ perror ("err: inet_pton error" );
106106 return -1 ;
107107 }
108108
109109 if (connect (* fd , (struct sockaddr * ) & cliaddr , sizeof (cliaddr )) < 0 ){
110- perror ("connect error" );
110+ perror ("err: connect error" );
111111 return -1 ;
112112 }
113113
@@ -147,21 +147,13 @@ int _ls(int controlfd, int datafd, char *input){
147147 memset (filelist , '\0' , (int )sizeof (filelist ));
148148
149149 if (get_filename (input , filelist ) > 0 ){
150- printf ( "Filelist Detected\n" );
150+
151151 sprintf (str , "ls %s" , filelist );
152152 printf ("Filelist: %s\n" , filelist );
153153 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- }*/
162154 DIR * dir = opendir (filelist );
163155 if (!dir ){
164- sprintf (sendline , "550 No Such File or Directory \n" );
156+ sprintf (sendline , "No such file or directory \n" );
165157 write (controlfd , sendline , strlen (sendline ));
166158 return -1 ;
167159 }else {closedir (dir );}
@@ -170,12 +162,12 @@ int _ls(int controlfd, int datafd, char *input){
170162 sprintf (str , "ls" );
171163 }
172164
173- // initiate file pointer for popen()
165+ // initiate file pointer for popen()
174166 FILE * in ;
175167 extern FILE * popen ();
176168
177169 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" );
179171 write (controlfd , sendline , strlen (sendline ));
180172 return -1 ;
181173 }
@@ -186,7 +178,7 @@ int _ls(int controlfd, int datafd, char *input){
186178 memset (sendline , '\0' , (int )sizeof (sendline ));
187179 }
188180
189- sprintf (sendline , "200 Command OK " );
181+ sprintf (sendline , "status: successful " );
190182 write (controlfd , sendline , strlen (sendline ));
191183 pclose (in );
192184
@@ -210,7 +202,7 @@ int _get(int controlfd, int datafd, char *input){
210202 }
211203 }else {
212204 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" );
214206 write (controlfd , sendline , strlen (sendline ));
215207 return -1 ;
216208 }
@@ -219,18 +211,17 @@ int _get(int controlfd, int datafd, char *input){
219211 extern FILE * popen ();
220212
221213 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" );
223215 write (controlfd , sendline , strlen (sendline ));
224216 return -1 ;
225217 }
226218
227219 while (fgets (sendline , MAXLINE , in ) != NULL ) {
228220 write (datafd , sendline , strlen (sendline ));
229- //printf("%s", sendline);
230221 memset (sendline , '\0' , (int )sizeof (sendline ));
231222 }
232223
233- sprintf (sendline , "200 Command OK " );
224+ sprintf (sendline , "status: successful " );
234225 write (controlfd , sendline , strlen (sendline ));
235226 pclose (in );
236227 return 1 ;
0 commit comments