Exemplo n.º 1
0
/* scan client and server files both*/
int scan_all(SSL *ssl)
{
	system("clear");
	logo_ui();
	list_server(ssl,49,LOGIN_USER.name,"-xF");	
	list_client(DOWNLOAD_DIR," --color=auto ");
}
Exemplo n.º 2
0
/* scan client's local files */
void scan_local_files(void)
{
	char scan_path[PATH_SIZE];

	memset(scan_path,0,sizeof(scan_path));
	system("clear");
	logo_ui();
	printf("Current files:\n");
	list_client(".","-lhF --color=auto");
	while(1)
	{
		if(get_path(scan_path,"Local directory or files") < 0)
				break;
		list_client(scan_path,"-lhF --color=auto");
	}
}
Exemplo n.º 3
0
/* download server's file */
int download_files(SSL *ssl,int order)
{
	int size;
	int ack,fd;
	char filename[FILENAME_SIZE];
	char localname[FILENAME_SIZE];
	SFT_PACK pack;
	SFT_DATA data;

	/* scan local and server files */
	scan_all(ssl);
	sftfile_userdir(DOWNLOAD_DIR);
	bzero(localname,sizeof(localname));
	/* input filename on server to download */
	sftfile_get_name(filename,"Download");
	if(strstr(filename,"..")!=NULL)
	{
		fprintf(stderr,"filename error: deny contain '..'\n");	
		return -1;
	}
	//sprintf(serv_path,"%s/%s",LOGIN_USER.name,filename);
	sprintf(data.file_attr.name,"%s/%s",LOGIN_USER.name,filename);

	cut_path(filename);
	sprintf(localname,"%s%s",DOWNLOAD_DIR,filename);
	/*send file information to server */
	sftpack_wrap(&pack,order,ASK,"");	
	pack.data = data;
	sftpack_send(ssl,&pack);
	/* receive server respond */
	sftpack_recv(ssl,&pack);
	ack =pack.ack;
	if(ack == ACCEPT)
	{
		size = pack.data.file_attr.size;
		fd = sftfile_open(localname,O_CREAT | O_TRUNC | O_RDWR);
		if(sftfile_recv(ssl,order,fd,size) == 0)
		{
			//size = sftfile_get_size(localname);	
			printf("Downlad %s succeed\n",filename);
			list_client(DOWNLOAD_DIR," --color=auto ");
			divline_ui();
		}	
		else
		{
			printf("Download %s failure!\n",filename);	
			return -1;
		}
	}

	return 0;
}
Exemplo n.º 4
0
/*main function*/
int main(int argc, char **argv)
{
    int opt;
    enum OPER_TYPE type;
    char path[FILE_NAME_LEN] = {0};
	char output_path[FILE_NAME_LEN] = {0};
    int delete_job;
    Client *c= NULL;
	
    if(argc<2)
  	    return -1;
	struct option long_options[] = {
		{"Simulate", 1, NULL, 'S'},
    	{"quit", 0, NULL, 'q'},
    	{"backup", 1, NULL, 'b'},
    	{"delete", 1, NULL, 'd'},
    	{"restore", 1, NULL, 'r'},
    	{"list", 0, NULL, 'l'},
    	{"pipeline", 0, NULL, 'p'},
    	{"output", 1, NULL, 'o'},
    	{"cloud", 0, NULL, 'c'},
    	
    	{"rewrite", 1, NULL, 'R'},
    	/*CFL*/
    	{"CFL", 1, NULL, 'C'},
    	{"seg_reuse", 1, NULL, 's'},
    	/*capping*/
    	{"cap_size", 1, NULL, 'a'},
    	{"cap_count", 1, NULL, 'e'},
    	/*perferect rewrite*/
    	{"ref_threshold", 1, NULL, 'u'},
    	
		{"overhead", 1, NULL, 'O'},
    	{"test", 1, NULL, 't'},
    	{"server", 1, NULL, 'H'},
    	{"help", 0, NULL, 'h'},
    	{NULL, 0, NULL, 0}
	};
	
    while((opt=getopt_long(argc, argv, "S:qb:d:r:lpo:cR:C:s:a:e:u:O:t:H:h", long_options, NULL))!=-1){
        switch(opt){
			case 'S':
				type=type_simulate;
				SIMULATE = true;
				strncpy(path, optarg, strlen(optarg));
				break;
            case 'q':
		        type=type_quit;
		        break;
            case 'b':
	  	        type=type_backup;
		        strncpy(path,optarg,strlen(optarg));
		        break;
            case 'd':
               	type=type_delete;
		        sscanf(optarg, "%d", &delete_job); 
		        break;
            case 'r':
              	type=type_restore;
		        strncpy(path,optarg,strlen(optarg));
		        break;
			case 'R':
				if (strcmp(optarg, "CFL") == 0)
					REWRITE = CFL_REWRITE;
				else if (strcmp(optarg, "CAP") == 0)
					REWRITE = CAPPING_REWRITE;
				else if (strcmp(optarg, "PER") == 0)
					REWRITE = PERFECT_REWRITE;
				break;
				
			case 'C':
				sscanf(optarg, "%f", &LWM);
				break;
			case 's':
				sscanf(optarg, "%f", &default_container_reuse);
				break;
			case 'a':
				sscanf(optarg, "%lld", &buffer_capacity);
				break;
			case 'e':
				sscanf(optarg, "%d", &max_refer_count);
				break;
			case 'u':
				sscanf(optarg, "%f", &segment_usage_threshold);
				break;
			case 'O':
				OVERHEAD = true;
				sscanf(optarg, "%f", &bandwidth);
				break;
	        case 't':
	  	        type=type_test;
		        strncpy(path,optarg,strlen(optarg));
		        break;
	        case 'h':
	   	        type=type_help;
		        break;
	            break;
            case 'H':
	  	        memset(SERVER_IP,0,30);
	  	        strncpy(SERVER_IP,optarg,strlen(optarg));
	  	        break;
			case 'l':
				type=type_list;
				break;
			case 'p':
				G_PIPELINE = true;
				break;
			case 'o':
				OUTPUT_RESULT = true;
				strncpy(output_path, optarg, strlen(optarg));
				break;
			case 'c':
				CLOUD = true;
				break;
	        default:
	   	        printf("Your command is wrong \n");
		        type=type_help;
		        break;
        }
    }

    if(type==type_help){
   	    usage(argv[0]);
	    return 0;
    }
    c = create_client();
	
	if (type == type_simulate) {
		simulata_backup(c, path, output_path);
		free(c);
		return 0;
	}else if(OVERHEAD == true) {
		backup_overhead(c, path, output_path);
		free(c);
		return 0;
	}
	
	
    if ((c->fd = bnet_connect(SERVER_IP, SERVER_PORT)) == -1){
	    err_msg1("Connection rejected!");
	    return 0;
    }

	if (G_PIPELINE) {
		c->recipe_fd = bnet_connect(SERVER_IP, SERVER_OTH_PORT);
		if (c->recipe_fd == -1) {
			err_msg1("Connection rejected!");
			return 0;
		}
	}
    
    if(type==type_test){
  	    test_data(c->fd, path);
	    return 0;
    }
    switch(type){
	    case type_login:
	        login(c);
	        break;
	    case type_logout:
	        logout(c);
	        break;
	    case type_quit:
            quit_client(c);
            break;
        case type_backup:
			if (G_PIPELINE)
				pipeline_backup(c, path, output_path);
			else
            	backup_client(c, path, output_path);
            break;
        case type_restore:
            restore_client(c, path, output_path);
            break;
        case type_delete:
            delete_client(c, delete_job);
            break;	
		case type_list:
			list_client(c);
			break;
	   default:
	   	    printf("Your command is wrong \n");
		    break;
    }
    free_client(c);
    return 0;
}