Exemple #1
0
static INT64_T do_get(int argc, char **argv)
{
	char target_full_path[CHIRP_PATH_MAX];
	char source_full_path[CHIRP_PATH_MAX];
	timestamp_t start, stop;
	double elapsed;
	INT64_T result;

	if(!argv[2])
		argv[2] = (char *) path_basename(argv[1]);

	complete_remote_path(argv[1], source_full_path);
	complete_local_path(argv[2], target_full_path);

	start = timestamp_get();
	result = chirp_recursive_get(current_host, source_full_path, target_full_path, stoptime);
	stop = timestamp_get();

	elapsed = (stop - start) / 1000000.0;

	if(result > 0) {
		printf("%sB read in %.2fs ", string_metric(result, -1, 0), elapsed);
		printf("(%sB/s)\n", string_metric(result / elapsed, -1, 0));
	}

	return result;
}
Exemple #2
0
static INT64_T do_get_one_dir(const char *hostport, const char *source_file, const char *target_file, int mode, time_t stoptime)
{
	char new_source_file[CHIRP_PATH_MAX];
	char new_target_file[CHIRP_PATH_MAX];
	struct list *work_list;
	const char *name;
	INT64_T result;
	INT64_T total = 0;

	work_list = list_create();

	result = mkdir(target_file, mode);
	if(result == 0 || errno == EEXIST) {
		result = chirp_reli_getdir(hostport, source_file, add_to_list, work_list, stoptime);
		if(result >= 0) {
			while((name = list_pop_head(work_list))) {
				if(!strcmp(name, "."))
					continue;
				if(!strcmp(name, ".."))
					continue;
				sprintf(new_source_file, "%s/%s", source_file, name);
				sprintf(new_target_file, "%s/%s", target_file, name);
				result = chirp_recursive_get(hostport, new_source_file, new_target_file, stoptime);
				free((char *) name);
				if(result < 0)
					break;
				total += result;
			}
		} else {
			result = -1;
		}
	} else {
		result = -1;
	}

	while((name = list_pop_head(work_list)))
		free((char *) name);

	list_delete(work_list);

	if(result >= 0) {
		return total;
	} else {
		return -1;
	}
}
int main(int argc, char *argv[])
{
    int did_explicit_auth = 0;
    int stdout_mode = 0;
    const char *hostname, *source_file, *target_file;
    time_t stoptime;
    FILE *file;
    INT64_T result;
    char c;
    char *tickets = NULL;

    debug_config(argv[0]);

    while((c = getopt(argc, argv, "a:d:i:t:vh")) != (char) -1) {
        switch (c) {
        case 'a':
            auth_register_byname(optarg);
            did_explicit_auth = 1;
            break;
        case 'd':
            debug_flags_set(optarg);
            break;
        case 'i':
            tickets = strdup(optarg);
            break;
        case 't':
            timeout = string_time_parse(optarg);
            break;
        case 'v':
            show_version(argv[0]);
            exit(0);
            break;
        case 'h':
            show_help(argv[0]);
            exit(0);
            break;

        }
    }

    if(!did_explicit_auth)
        auth_register_all();
    if(tickets) {
        auth_ticket_load(tickets);
        free(tickets);
    } else if(getenv(CHIRP_CLIENT_TICKETS)) {
        auth_ticket_load(getenv(CHIRP_CLIENT_TICKETS));
    } else {
        auth_ticket_load(NULL);
    }

    if((argc - optind) < 3) {
        show_help(argv[0]);
        exit(0);
    }

    hostname = argv[optind];
    source_file = argv[optind + 1];
    target_file = argv[optind + 2];
    stoptime = time(0) + timeout;

    if(!strcmp(target_file, "-")) {
        stdout_mode = 1;
        file = stdout;
    }

    if(stdout_mode) {
        result = chirp_reli_getfile(hostname, source_file, file, stoptime);
    } else {
        result = chirp_recursive_get(hostname, source_file, target_file, stoptime);
    }

    if(result < 0) {
        fprintf(stderr, "couldn't get %s:%s: %s\n", hostname, source_file, strerror(errno));
        return 1;
    } else {
        return 0;
    }
}