~ubuntu-branches/ubuntu/vivid/cctools/vivid

« back to all changes in this revision

Viewing changes to chirp/src/chirp_get.c

  • Committer: Bazaar Package Importer
  • Author(s): Michael Hanke
  • Date: 2011-05-07 09:05:00 UTC
  • Revision ID: james.westby@ubuntu.com-20110507090500-lqpmdtwndor6e7os
Tags: upstream-3.3.2
ImportĀ upstreamĀ versionĀ 3.3.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
Copyright (C) 2003-2004 Douglas Thain and the University of Wisconsin
 
3
Copyright (C) 2005- The University of Notre Dame
 
4
This software is distributed under the GNU General Public License.
 
5
See the file COPYING for details.
 
6
*/
 
7
 
 
8
#include <stdio.h>
 
9
#include <errno.h>
 
10
#include <string.h>
 
11
#include <stdlib.h>
 
12
#include <dirent.h>
 
13
#include <time.h>
 
14
 
 
15
#include "chirp_reli.h"
 
16
#include "chirp_recursive.h"
 
17
 
 
18
#include "debug.h"
 
19
#include "auth_all.h"
 
20
#include "stringtools.h"
 
21
#include "xmalloc.h"
 
22
#include "full_io.h"
 
23
 
 
24
static int timeout=3600;
 
25
 
 
26
static void show_version( const char *cmd )
 
27
{
 
28
        printf("%s version %d.%d.%d built by %s@%s on %s at %s\n",cmd,CCTOOLS_VERSION_MAJOR,CCTOOLS_VERSION_MINOR,CCTOOLS_VERSION_MICRO,BUILD_USER,BUILD_HOST,__DATE__,__TIME__);
 
29
}
 
30
 
 
31
static void show_help( const char *cmd )
 
32
{
 
33
        printf("use: %s [options] <hostname[:port]> <remote-file> <local-file>\n",cmd);
 
34
        printf("where options are:\n");
 
35
        printf(" -a <flag>  Require this authentication mode.\n");
 
36
        printf(" -d <flag>  Enable debugging for this subsystem.\n");
 
37
        printf(" -t <time>  Timeout for failure. (default is %ds)\n",timeout);
 
38
        printf(" -v         Show program version.\n");
 
39
        printf(" -h         This message.\n");
 
40
}
 
41
 
 
42
int main( int argc, char *argv[] )
 
43
{       
 
44
        int did_explicit_auth = 0;
 
45
        int stdout_mode = 0;
 
46
        const char *hostname, *source_file, *target_file;
 
47
        time_t stoptime;
 
48
        FILE *file;
 
49
        INT64_T result;
 
50
        char c;
 
51
 
 
52
        debug_config(argv[0]);
 
53
 
 
54
        while((c=getopt(argc,argv,"a:d:t:vh"))!=(char)-1) {
 
55
                switch(c) {
 
56
                        case 'a':
 
57
                                auth_register_byname(optarg);
 
58
                                did_explicit_auth = 1;
 
59
                                break;
 
60
                        case 'd':
 
61
                                debug_flags_set(optarg);
 
62
                                break;
 
63
                        case 't':
 
64
                                timeout = string_time_parse(optarg);
 
65
                                break;
 
66
                        case 'v':
 
67
                                show_version(argv[0]);
 
68
                                exit(0);
 
69
                                break;
 
70
                        case 'h':
 
71
                                show_help(argv[0]);
 
72
                                exit(0);
 
73
                                break;
 
74
 
 
75
                }
 
76
        }
 
77
 
 
78
        if(!did_explicit_auth) auth_register_all();
 
79
 
 
80
        if( (argc-optind)<3 ) {
 
81
                show_help(argv[0]);
 
82
                exit(0);
 
83
        }
 
84
 
 
85
        hostname = argv[optind];
 
86
        source_file = argv[optind+1];
 
87
        target_file = argv[optind+2];
 
88
        stoptime = time(0) + timeout;
 
89
 
 
90
        if(!strcmp(target_file,"-")) {
 
91
                stdout_mode = 1;
 
92
                file = stdout;
 
93
        }
 
94
 
 
95
        if (stdout_mode) {
 
96
                result = chirp_reli_getfile(hostname,source_file,file,stoptime);
 
97
        } else {
 
98
                result = chirp_recursive_get(hostname,source_file,target_file,stoptime);
 
99
        }
 
100
 
 
101
        if(result<0) {
 
102
                fprintf(stderr,"couldn't get %s:%s: %s\n",hostname,source_file,strerror(errno));
 
103
                return 1;
 
104
        } else {
 
105
                return 0;
 
106
        }
 
107
}
 
108