1 /***************************************************************************/
2 /*                                                                         */
3 /* Fast Webpage Exchanger - an FTP client for updating webpages            */
4 /* Copyright (C) 1999-2000 Yuuki NINOMIYA <gm@debian.or.jp>                */
5 /*                                                                         */
6 /* This program is free software; you can redistribute it and/or modify    */
7 /* it under the terms of the GNU General Public License as published by    */
8 /* the Free Software Foundation; either version 2, or (at your option)     */
9 /* any later version.                                                      */
10 /*                                                                         */
11 /* This program is distributed in the hope that it will be useful,         */
12 /* but WITHOUT ANY WARRANTY; without even the implied warranty of          */
13 /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the           */
14 /* GNU General Public License for more details.                            */
15 /*                                                                         */
16 /* You should have received a copy of the GNU General Public License       */
17 /* along with this program; if not, write to the                           */
18 /* Free Software Foundation, Inc., 59 Temple Place - Suite 330,            */
19 /* Boston, MA 02111-1307, USA.                                             */
20 /*                                                                         */
21 /***************************************************************************/
22 
23 #ifdef HAVE_CONFIG_H
24 #  include "config.h"
25 #endif
26 
27 #include <stdio.h>
28 #include <stdlib.h>
29 #include <string.h>
30 #include <unistd.h>
31 #include <ctype.h>
32 #include <sys/stat.h>
33 #include "intl.h"
34 #include "ftplib.h"
35 #include "strlib.h"
36 #include "variable.h"
37 #include "proto.h"
38 
39 
40 static int total_sent_file;
41 static int total_removed_file;
42 
43 
44 /* --------------------------------------------------
45  NAME       ftp_main
46  FUNCTION   main loop of sending
47  INPUT      argc ... argument counter
48             argv ... argument vector
49             max_hosts ... maximum hosts in the configuration file
50  OUTPUT     none
51 -------------------------------------------------- */
ftp_main(int argc,char * argv[],int max_hosts)52 void ftp_main(int argc,char *argv[],int max_hosts)
53 {
54 	int i;
55 	char *temp;
56 
57 	FtpInit();
58 
59 	for(i=0;i<argc-1;i++){
60 		host_number=argv_to_host_num(argv[i+1]);
61 
62 		if(argc-1>1){
63 			put_mes(PROCESS,0,cfgSectionNumberToName(host_number),NULL);
64 		}
65 
66 		if(ftp_connect_init()==-1){
67 			log_flush();
68 			continue;
69 		}
70 		total_sent_file=total_removed_file=0;
71 		ftp_recursive_search();
72 
73 		put_mes(LEAVE,0,dest_dir[host_number],NULL);
74 		temp=str_dup_printf(_("Complete: sent %d file(s), removed %d file(s)"),total_sent_file,total_removed_file);
75 		log_write(temp);
76 		free(temp);
77 		ftp_disconnect();
78 		if(!opt_test){
79 			save_cache();
80 		}
81 	}
82 }
83 
84 
85 /* --------------------------------------------------
86  NAME       argv_to_host_num
87  FUNCTION   conver the argument(name or number) to host number
88  INPUT      arg ... argument
89  OUTPUT     host number
90 -------------------------------------------------- */
argv_to_host_num(char * arg)91 int argv_to_host_num(char *arg)
92 {
93 	int num;
94 
95 	num=atoi(arg)-1;
96 	if(num==-1){
97 		num=cfgSectionNameToNumber(arg);
98 		if(num==-1){
99 			fprintf(stderr,_("Specified host (section) name `%s' is undefined.\n"),arg);
100 			exit(1);
101 		}
102 	}else{
103 		if(cfgSectionNumberToName(num)==NULL){
104 			fprintf(stderr,_("Specified host (section) number `%s' is undefined.\n"),arg);
105 			exit(1);
106 		}
107 	}
108 	if(strcasecmp("default",cfgSectionNumberToName(num))==0){
109 		fprintf(stderr,_("Cannot specify a default configuration.\n"));
110 		exit(1);
111 	}
112 
113 	return(num);
114 }
115 
116 
117 /* --------------------------------------------------
118  NAME       ftp_connect_init
119  FUNCTION   connect and login
120  OUTPUT     0  ... success
121             -1 ... fail
122 -------------------------------------------------- */
ftp_connect_init(void)123 int ftp_connect_init(void)
124 {
125 	char *temp;
126 
127 	log_init();
128 
129 	put_mes(CONNECT,0,host_name[host_number],NULL);
130 	if(ftp_connect()==-1){
131 		return(-1);
132 	}
133 	if(ftp_login()==-1){
134 		return(-1);
135 	}
136 
137 	load_cache();
138 
139 	current_dir[LOCAL]=NULL;
140 	if(src_dir[host_number]==NULL){
141 		fprintf(stderr,_("The source directory (SrcDir) is not configured.\n"));
142 		exit(1);
143 	}
144 	change_dir(src_dir[host_number],LOCAL);
145 
146 	current_dir[REMOTE]=NULL;
147 	if(dest_dir[host_number]==NULL){
148 		fprintf(stderr,_("The destination directory (DestDir) is not configured.\n"));
149 		exit(1);
150 	}
151 
152 	change_dir(dest_dir[host_number],REMOTE);
153 	if(chdir_at_connection[host_number]){
154 		if(!is_cache_existent){
155 			temp=str_dup(dest_dir[host_number]);
156 			if(strcmp(temp,"/")!=0){
157 				temp[strlen(temp)-1]='\0';
158 			}
159 			if(FtpChdir(temp,ftp_buf)==0){
160 				if(FtpMkdir(temp,ftp_buf)==1){
161 					put_mes(MKDIR,0,dest_dir[host_number],NULL);
162 				}
163 				FtpChdir(temp,ftp_buf);
164 			}
165 			free(temp);
166 		}else{
167 			change_dir_actually(REMOTE);
168 		}
169 	}
170 	put_mes(ENTER,0,dest_dir[host_number],NULL);
171 
172 	return(0);
173 }
174 
175 
176 /* --------------------------------------------------
177  NAME       ftp_connect
178  FUNCTION   connect the host
179  OUTPUT     0  ... success
180             -1 ... fail
181 -------------------------------------------------- */
ftp_connect(void)182 int ftp_connect(void)
183 {
184 	char *temp;
185 
186 	if(host_name[host_number]==NULL){
187 		fprintf(stderr,_("The host name is not configured.\n"));
188 		exit(1);
189 	}
190 	if(!FtpConnect(host_name[host_number],&ftp_buf, host_use_SSL[host_number])){
191 		fprintf(stderr,_("Cannot connect host `%s'.\n\n"),host_name[host_number]);
192 		temp=str_dup_printf(_("Connection failed: %s (%s)"),host_name[host_number],cfgSectionNumberToName(host_number));
193 		log_write(temp);
194 		free(temp);
195 		return(-1);
196 	}
197 	temp=str_dup_printf(_("Connected: %s (%s)"),host_name[host_number],cfgSectionNumberToName(host_number));
198 	log_write(temp);
199 	free(temp);
200 
201 	return(0);
202 }
203 
204 
205 /* --------------------------------------------------
206  NAME       ftp_disconnect
207  FUNCTION   disconnect the host
208  OUTPUT     none
209 -------------------------------------------------- */
ftp_disconnect(void)210 void ftp_disconnect(void)
211 {
212 	char *temp;
213 
214 	put_mes(DISCONNECT,0,host_name[host_number],NULL);
215 
216 	if(!cfg_silent[host_number] && !opt_silent){
217 		printf("\n");
218 	}
219 
220 	FtpQuit(ftp_buf);
221 	free(current_dir[LOCAL]);
222 	free(current_dir[REMOTE]);
223 
224 	temp=str_dup_printf(_("Disconnected: %s (%s)"),host_name[host_number],cfgSectionNumberToName(host_number));
225 	log_write(temp);
226 	free(temp);
227 
228 	log_flush();
229 }
230 
231 
232 /* --------------------------------------------------
233  NAME       ftp_login
234  FUNCTION   login to the host
235  OUTPUT     0  ... success
236             -1 ... fail
237 -------------------------------------------------- */
ftp_login(void)238 int ftp_login(void)
239 {
240 	if(login_name[host_number]==NULL){
241 		fprintf(stderr,_("The login name is not configured.\n"));
242 		exit(1);
243 	}
244 	if(password[host_number]==NULL){
245 		/* Changed by Waleed Kadous <waleed@cse.unsw.edu.au> to ask
246 		   for a password if none is given in the weexrc file */
247 		fprintf(stderr,_("No password specified in configuration file for `%s'. Asking ...\n"),host_name[host_number]);
248 		password[host_number]=str_dup(getpass(_("Password:")));
249 	}
250 	if(!FtpLogin(login_name[host_number],password[host_number],ftp_buf)){
251 		char *temp;
252 
253 		fprintf(stderr,_("Login failed. Check your ID and password.\n\n"));
254 		temp=str_dup_printf(_("Login failed: %s (%s)"),host_name[host_number],cfgSectionNumberToName(host_number));
255 		log_write(temp);
256 		free(temp);
257 		return(-1);
258 	}
259 	if(authorization_name[host_number]){
260 	  while(!FtpAuthorize(authorization_name[host_number], ftp_buf)){
261 	    fprintf(stderr,_("Authorization failed; try again\n\n"));
262 	  }
263 	}
264 	return(0);
265 }
266 
267 
268 /* --------------------------------------------------
269  NAME       change_dir
270  FUNCTION   change the current working directory
271  INPUT      path ... change to path
272             side ... LOCAL or REMOTE
273  OUTPUT     none
274 -------------------------------------------------- */
change_dir(char * path,LocalOrRemote side)275 void change_dir(char *path,LocalOrRemote side)
276 {
277 	if(current_dir[side]==NULL){
278 		current_dir[side]=str_dup(path);
279 	}else{
280 		current_dir[side]=str_realloc(current_dir[side],strlen(current_dir[side])+strlen(path)+2);
281 		strcat(current_dir[side],path);
282 		strcat(current_dir[side],"/");
283 	}
284 
285 	if(side==LOCAL){
286 		change_dir_actually(LOCAL);
287 	}
288 }
289 
290 
291 /* --------------------------------------------------
292  NAME       up_dir
293  FUNCTION   change the current working directory to the parent one
294  INPUT      side ... LOCAL or REMOTE
295  OUTPUT     none
296 -------------------------------------------------- */
up_dir(LocalOrRemote side)297 void up_dir(LocalOrRemote side)
298 {
299 	*strrchr(current_dir[side],'/')='\0';
300 	*(strrchr(current_dir[side],'/')+1)='\0';
301 	current_dir[side]=str_realloc(current_dir[side],strlen(current_dir[side])+1);
302 
303 	if(side==LOCAL){
304 		change_dir_actually(LOCAL);
305 	}
306 }
307 
308 
change_dir_actually(LocalOrRemote side)309 void change_dir_actually(LocalOrRemote side)
310 {
311 	char *temp;
312 
313 	temp=str_dup(current_dir[side]);
314 	if(strcmp(temp,"/")!=0){
315 		temp[strlen(temp)-1]='\0';
316 	}
317 	if((side==LOCAL && chdir(temp)==-1) || (side==REMOTE && FtpChdir(temp,ftp_buf)==0)){
318 		free(temp);
319 		fprintf(stderr,_("Cannot change %s current working directory to `%s'.\n"),side==LOCAL ? _("local") : _("remote"),current_dir[side]);
320 		temp=str_dup_printf(_("Changing %s current working directory failed: %s"),side==LOCAL ? _("local") : _("remote"),current_dir[side]);
321 		log_write(temp);
322 		free(temp);
323 		ftp_disconnect();
324 		exit(1);
325 	}
326 	free(temp);
327 }
328 
329 
330 /* --------------------------------------------------
331  NAME       ftp_recursive_search
332  FUNCTION   search files and directories recursively
333  OUTPUT     none
334 -------------------------------------------------- */
ftp_recursive_search(void)335 void ftp_recursive_search(void)
336 {
337 	static int dir_nest=1;
338 	FileData *local_data=NULL;
339 	FileData *remote_data=NULL;
340 	int max_local_file;
341 	int max_remote_file;
342 	char *file_name;
343 	int remote_num;
344 	int trans_mode;
345 	int i,j;
346 	int opt_silent_bak;
347 	char *temp;
348 	char *put_temp;
349 	char *mode_temp=NULL;
350 	int dir_sent_file=0;
351 	int dir_removed_file=0;
352 
353 	max_local_file=get_local_file_data(&local_data);
354 	max_remote_file=get_remote_file_data_from_cache(&remote_data);
355 
356 	for(i=0;i<max_local_file;i++){
357 		if(conv_to_lower[host_number]){
358 			file_name=str_tolower(local_data[i].name);
359 		}else{
360 			file_name=local_data[i].name;
361 		}
362 		remote_num=get_equivalent_remote_number(file_name,max_remote_file,remote_data);
363 		DebugPrint((stderr,"remote_num of `%s' is %d\n",file_name,remote_num));
364 		if(local_data[i].isdir){
365 			change_dir(file_name,LOCAL);
366 			ftp_enter(file_name,(remote_num==-1) ? 0 : remote_data[remote_num].isdir,dir_nest,remote_num,&dir_removed_file);
367 
368 			dir_nest++;
369 			ftp_recursive_search();
370 			dir_nest--;
371 
372 			put_mes(LEAVE,dir_nest,current_dir[REMOTE],NULL);
373 			up_dir(LOCAL);
374 			up_dir(REMOTE);
375 			if(conv_to_lower[host_number]){
376 				free(file_name);
377 			}
378 			continue;
379 		}else if(remote_num!=-1 && remote_data[remote_num].isdir){
380 
381 			remove_remote_dir(file_name,dir_nest,&dir_removed_file);
382 		}
383 
384 		if(opt_force || cfg_force[host_number] || remote_num==-1 ||
385 		   remote_data[remote_num].isdir ||
386 		   local_data[i].date>remote_data[remote_num].date ||
387 		  (local_data[i].date==remote_data[remote_num].date &&
388 		   local_data[i].time>remote_data[remote_num].time)){
389 			if(!overwrite_ok[host_number] && !rename_ok[host_number]){
390 				ftp_remove(file_name,dir_nest,&dir_removed_file);
391 			}
392 			if(is_ascii_file(file_name)){
393 				trans_mode=FTPLIB_ASCII;
394 				if(conv_to_lower[host_number] && strcmp(local_data[i].name,file_name)!=0){
395 					put_mes(ASCII_LOWER_SEND,dir_nest,local_data[i].name,file_name,NULL);
396 				}else{
397 					put_mes(ASCII_SEND,dir_nest,file_name,NULL);
398 				}
399 			}else{
400 				trans_mode=FTPLIB_IMAGE;
401 				if(conv_to_lower[host_number] && strcmp(local_data[i].name,file_name)!=0){
402 					put_mes(BINARY_LOWER_SEND,dir_nest,local_data[i].name,file_name,NULL);
403 				}else{
404 					put_mes(BINARY_SEND,dir_nest,file_name,NULL);
405 				}
406 			}
407 			if(!opt_test){
408 			        int success = 0;
409 				opt_silent_bak=opt_silent;
410 				if(cfg_silent[host_number]){
411 					opt_silent=1;
412 				}
413 				if (rename_ok[host_number]) {
414 				  put_temp=str_concat(current_dir[REMOTE],"weex.tmp",NULL);
415 				} else {
416 				  put_temp=str_concat(current_dir[REMOTE],file_name,NULL);
417 				}
418 				for(j=0;;j++){
419 					if(FtpPut(local_data[i].name,put_temp,trans_mode,ftp_buf)==1){
420 						if(log_detail_level[host_number]>=3){
421 							temp=str_dup_printf(_("Sent: %s%s"),current_dir[REMOTE],file_name);
422 							log_write(temp);
423 							free(temp);
424 						}
425 						dir_sent_file++;
426 						update_cache(file_name,local_data[i].date,local_data[i].time);
427 						/* save the cache after each upload */
428 						save_cache();
429 
430 						if(is_change_permission_dir()){
431 							mode_temp=str_dup(change_permission[host_number]);
432 						}else if(is_preserve_permission_dir()){
433 							struct stat local_file_stat;
434 
435 							stat(file_name,&local_file_stat);
436 							mode_temp=str_dup_printf("%o",local_file_stat.st_mode & 0777);
437 						}
438 
439 						if(is_preserve_permission_dir() || is_change_permission_dir()){
440 							put_mes(CHMOD,dir_nest,file_name,NULL);
441 							if(FtpChmod(put_temp,mode_temp,ftp_buf)==0){
442 								fprintf(stderr,_("Cannot change the access permissions of `%s%s' to `%s'.\n"),current_dir[REMOTE],file_name,change_permission[host_number]);
443 								temp=str_dup_printf(_("Changing the access permissions failed: %s%s"),current_dir[REMOTE],file_name);
444 								log_write(temp);
445 								free(temp);
446 							}
447 							free(mode_temp);
448 						}
449 						success = 1;
450 						break;
451 					}
452 					if(j>=max_retry_to_send[host_number]){
453 						fprintf(stderr,_("Cannot send file `%s%s'.\n"),current_dir[REMOTE],file_name);
454 						temp=str_dup_printf(_("Sending failed: %s%s"),current_dir[REMOTE],file_name);
455 						log_write(temp);
456 						free(temp);
457 
458 						break;
459 					}
460 					temp=str_dup_printf(_("Retry to send: %s%s"),current_dir[REMOTE],file_name);
461 					log_write(temp);
462 					free(temp);
463 					fprintf(stderr,_("Retrying...\n"));
464 				}
465 				if (success && rename_ok[host_number]) {
466 				  char *put_temp2;
467 				  if(!overwrite_ok[host_number]){
468 				    ftp_remove(file_name,dir_nest,&dir_removed_file);
469 				  }
470 				  put_temp2 = str_concat(current_dir[REMOTE],file_name,NULL);
471 				  if (!FtpRename(put_temp, put_temp2, ftp_buf)) {
472 				    fprintf(stderr,_("Cannot rename temporary file to `%s%s'.\n"),current_dir[REMOTE],file_name);
473 				    temp=str_dup_printf(_("Sending failed: %s%s"),current_dir[REMOTE],file_name);
474 				    log_write(temp);
475 				    free(temp);
476 				  }
477 				  free(put_temp2);
478 				}
479 				free(put_temp);
480 				opt_silent=opt_silent_bak;
481 			}
482 		}
483 		if(conv_to_lower[host_number]){
484 			free(file_name);
485 		}
486 	}
487 	remove_files_on_remote_only(max_local_file,max_remote_file,local_data,remote_data,dir_nest,&dir_removed_file);
488 
489 	free_file_data(local_data,max_local_file);
490 	free_file_data(remote_data,max_remote_file);
491 
492 	total_sent_file+=dir_sent_file;
493 	total_removed_file+=dir_removed_file;
494 
495 	if(log_detail_level[host_number]>=2){
496 		temp=str_dup_printf(_("%s : sent %d file(s), removed %d file(s)"),current_dir[REMOTE],dir_sent_file,dir_removed_file);
497 		log_write(temp);
498 		free(temp);
499 	}
500 }
501 
502 
503 /* --------------------------------------------------
504  NAME       remove_files_on_remote_only
505  FUNCTION   remove the files on the remote side only
506  INPUT      max_local_file .... the maximum number of local files
507             max_remote_file ... the maximum number of remote files
508             local_data .... local file data
509             remote_data ... remote file data
510             dir_nest ...... nest level of directory
511             dir_removed_file ... the number of removed files in the directory
512  OUTPUT     none
513 -------------------------------------------------- */
remove_files_on_remote_only(int max_local_file,int max_remote_file,FileData * local_data,FileData * remote_data,int dir_nest,int * dir_removed_file)514 void remove_files_on_remote_only(int max_local_file,int max_remote_file,FileData *local_data,FileData *remote_data,int dir_nest,int *dir_removed_file)
515 {
516 	int i;
517 	int local_num;
518 	char *file_name;
519 
520 	for(i=0;i<max_remote_file;i++){
521 		file_name=remote_data[i].name;
522 		local_num=get_equivalent_local_number(file_name,max_local_file,local_data);
523 		if(local_num==-1){
524 			if(remote_data[i].isdir){
525 				remove_remote_dir(file_name,dir_nest,dir_removed_file);
526 			}else{
527 				ftp_remove(file_name,dir_nest,dir_removed_file);
528 			}
529 		}
530 	}
531 }
532 
533 
534 /* --------------------------------------------------
535  NAME       get_equivalent_remote_number
536  FUNCTION   get remote file number equivalent to local one
537  INPUT      local_name ... file name of the local file
538             max_remote_file ... the maximum number of remote files
539             remote_data ... remote file data
540  OUTPUT     remote file number equivalent to local one
541             return -1 if no equivalent file
542 -------------------------------------------------- */
get_equivalent_remote_number(char * local_name,int max_remote_file,FileData * remote_data)543 int get_equivalent_remote_number(char *local_name,int max_remote_file,FileData *remote_data)
544 {
545 	int i;
546 
547 	for(i=0;i<max_remote_file;i++){
548 		if(strcmp(local_name,remote_data[i].name)==0){
549 			return(i);
550 		}
551 	}
552 	return(-1);
553 }
554 
555 
556 /* --------------------------------------------------
557  NAME       get_equivalent_local_number
558  FUNCTION   get local file number equivalent to remote one
559  INPUT      remote_name ... file name of the remote file
560             max_local_file ... the maximum number of local files
561             local_data ... local file data
562  OUTPUT     local file number equivalent to remote one
563             return -1 if no equivalent file
564 -------------------------------------------------- */
get_equivalent_local_number(char * remote_name,int max_local_file,FileData * local_data)565 int get_equivalent_local_number(char *remote_name,int max_local_file,FileData *local_data)
566 {
567 	int i;
568 
569 	for(i=0;i<max_local_file;i++){
570 		if(conv_to_lower[host_number]){
571 			if(strcasecmp(remote_name,local_data[i].name)==0){
572 				return(i);
573 			}
574 		}else{
575 			if(strcmp(remote_name,local_data[i].name)==0){
576 				return(i);
577 			}
578 		}
579 	}
580 	return(-1);
581 }
582 
583 
584 /* --------------------------------------------------
585  NAME       ftp_enter
586  FUNCTION   enter the directory in remote
587  INPUT      dir_name ....... name of entered directory
588             remote_isdir ... whether equivalent remote file is directory
589             dir_level ...... nest level of directory
590             remote_num ..... equivalent remote file number
591             dir_removed_file ... the number of removed files in the directory
592  OUTPUT     none
593 -------------------------------------------------- */
ftp_enter(char * dir_name,int remote_isdir,int dir_nest,int remote_num,int * dir_removed_file)594 void ftp_enter(char *dir_name,int remote_isdir,int dir_nest,int remote_num,int *dir_removed_file)
595 {
596 	if(remote_num==-1){
597 		put_mes(MKDIR,dir_nest,current_dir[REMOTE],dir_name,"/",NULL);
598 		DebugPrint((stderr,"FtpMkdir: %s(remote_num==-1)\n",dir_name));
599 
600 		ftp_mkdir(dir_name);
601 	}else if(!remote_isdir){
602 		ftp_remove(dir_name,dir_nest,dir_removed_file);
603 
604 		put_mes(MKDIR,dir_nest,current_dir[REMOTE],dir_name,"/",NULL);
605 		DebugPrint((stderr,"FtpMkdir: %s(remote_num!=-1 and !isdir)\n",dir_name));
606 
607 		ftp_mkdir(dir_name);
608 	}
609 
610 	put_mes(ENTER,dir_nest,current_dir[REMOTE],dir_name,"/",NULL);
611 
612 	update_cache(dir_name,99999999,999999);
613 
614 	change_dir(dir_name,REMOTE);
615 }
616 
617 
618 /* --------------------------------------------------
619  NAME       ftp_remove
620  FUNCTION   remove the remote file
621  INPUT      file_name ....... remote file that you want to remove
622             dir_nest ........ nest level of directory
623             dir_removed_file ... the number of removed files in the directory
624  OUTPUT     none
625 -------------------------------------------------- */
ftp_remove(char * file_name,int dir_nest,int * dir_removed_file)626 void ftp_remove(char *file_name,int dir_nest,int *dir_removed_file)
627 {
628 	char *temp;
629 	char *del_temp;
630 
631 	if(is_keep_remote_dir()){
632 		return;
633 	}
634 	put_mes(REMOVE,dir_nest,file_name,NULL);
635 	if(opt_test){
636 		return;
637 	}
638 	del_temp=str_concat(current_dir[REMOTE],file_name,NULL);
639 	if(FtpDelete(del_temp,ftp_buf)==0){
640 		fprintf(stderr,_("Cannot remove remote file `%s%s'.\n"),current_dir[REMOTE],file_name);
641 		temp=str_dup_printf(_("Removing failed: %s%s"),current_dir[REMOTE],file_name);
642 		log_write(temp);
643 		free(temp);
644 	}else{
645 		if(log_detail_level[host_number]>=3){
646 			temp=str_dup_printf(_("Removed: %s%s"),current_dir[REMOTE],file_name);
647 			log_write(temp);
648 			free(temp);
649 		}
650 		(*dir_removed_file)++;
651 		del_cache(file_name);
652 	}
653 	free(del_temp);
654 }
655 
656 
657 /* --------------------------------------------------
658  NAME       remove_remote_dir
659  FUNCTION   remove the remote directory recursively
660  INPUT      dir_name ... name of the remote directory that you want to remove
661             dir_nest ... nest level of directory
662             dir_removed_file ... the number of removed files in the directory
663  OUTPUT     none
664 -------------------------------------------------- */
remove_remote_dir(char * dir_name,int dir_nest,int * dir_removed_file)665 void remove_remote_dir(char *dir_name,int dir_nest,int *dir_removed_file)
666 {
667 	FileData *remote_data=NULL;
668 	int max_remote_file;
669 	char *file_name;
670 	int i;
671 	char *rm_temp;
672 
673 	put_mes(ENTER,dir_nest,current_dir[REMOTE],dir_name,"/",NULL);
674 	change_dir(dir_name,REMOTE);
675 
676 	if(is_keep_remote_dir()){
677 		put_mes(LEAVE,dir_nest,current_dir[REMOTE],NULL);
678 		up_dir(REMOTE);
679 		return;
680 	}
681 
682 	dir_nest++;
683 
684 	max_remote_file=get_remote_file_data_from_cache(&remote_data);
685 	for(i=0;i<max_remote_file;i++){
686 		file_name=remote_data[i].name;
687 		if(remote_data[i].isdir){
688 			remove_remote_dir(file_name,dir_nest,dir_removed_file);
689 		}else{
690 			ftp_remove(file_name,dir_nest,dir_removed_file);
691 		}
692 	}
693 
694 	dir_nest--;
695 	put_mes(LEAVE,dir_nest,current_dir[REMOTE],NULL);
696 	up_dir(REMOTE);
697 	put_mes(REMOVE,dir_nest,current_dir[REMOTE],dir_name,"/",NULL);
698 	if(opt_test){
699 		return;
700 	}
701 	if(!is_cache_existent){
702 		change_dir_actually(REMOTE);
703 	}
704 	rm_temp=str_concat(current_dir[REMOTE],dir_name,NULL);
705 	if(FtpRmdir(rm_temp,ftp_buf)==0){
706 		char *temp;
707 
708 		fprintf(stderr,_("Cannot remove remote directory `%s%s/'.\n"),current_dir[REMOTE],dir_name);
709 		temp=str_dup_printf(_("Removing failed: %s%s/"),current_dir[REMOTE],dir_name);
710 		log_write(temp);
711 		free(temp);
712 	}else{
713 		del_cache(dir_name);
714 		del_cache_dir(dir_name);
715 	}
716 	free(rm_temp);
717 }
718 
719 
720 /* --------------------------------------------------
721  NAME       ftp_mkdir
722  FUNCTION   make the directory
723  INPUT      dir_name ... name of directory that you want to create
724  OUTPUT     none
725 -------------------------------------------------- */
ftp_mkdir(char * dir_name)726 void ftp_mkdir(char *dir_name)
727 {
728 	char *temp;
729 
730 	if(opt_test){
731 		return;
732 	}
733 	temp=str_concat(current_dir[REMOTE],dir_name,NULL);
734 	if(FtpMkdir(temp,ftp_buf)==0){
735 		free(temp);
736 		fprintf(stderr,_("Cannot make remote directory `%s%s/'.\n"),current_dir[REMOTE],dir_name);
737 		temp=str_dup_printf(_("Making directory failed: %s%s/"),current_dir[REMOTE],dir_name);
738 		log_write(temp);
739 		free(temp);
740 		ftp_disconnect();
741 		exit(1);
742 	}
743 	free(temp);
744 }
745 
746 
747 
748