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.
16
#include "chirp_reli.h"
17
#include "chirp_recursive.h"
18
#include "chirp_stream.h"
22
#include "stringtools.h"
26
#if CCTOOLS_OPSYS_CYGWIN || CCTOOLS_OPSYS_DARWIN || CCTOOLS_OPSYS_FREEBSD
33
#define fseeko64 fseeko
36
static int timeout=3600;
37
static int buffer_size=65536;
39
static void show_version( const char *cmd )
41
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__);
44
static void show_help( const char *cmd )
46
printf("use: %s [options] <local-file> <hostname[:port]> <remote-file>\n",cmd);
47
printf("where options are:\n");
48
printf(" -a <flag> Require this authentication mode.\n");
49
printf(" -b <size> Set transfer buffer size. (default is %d bytes)\n",buffer_size);
50
printf(" -d <flag> Enable debugging for this subsystem.\n");
51
printf(" -f Follow input file like tail -f.\n");
52
printf(" -t <time> Timeout for failure. (default is %ds)\n",timeout);
53
printf(" -v Show program version.\n");
54
printf(" -h This message.\n");
57
int main( int argc, char *argv[] )
59
int did_explicit_auth = 0;
61
int whole_file_mode = 1;
62
const char *hostname, *source_file, *target_file;
67
debug_config(argv[0]);
69
while((c=getopt(argc,argv,"a:b:d:ft:vh"))!=(char)-1) {
72
auth_register_byname(optarg);
73
did_explicit_auth = 1;
76
buffer_size = atoi(optarg);
79
debug_flags_set(optarg);
85
timeout = string_time_parse(optarg);
88
show_version(argv[0]);
99
if(!did_explicit_auth) auth_register_all();
101
if( (argc-optind)<3 ) {
106
source_file = argv[optind];
107
hostname = argv[optind+1];
108
target_file = argv[optind+2];
109
stoptime = time(0) + timeout;
111
if(!strcmp(source_file,"-")) {
113
source_file = "/dev/stdin";
115
file = fopen(source_file,"r");
117
fprintf(stderr,"chirp_put: couldn't open %s: %s\n",source_file,strerror(errno));
122
if(follow_mode) whole_file_mode = 0;
124
if(whole_file_mode) {
125
int result = chirp_recursive_put(hostname,source_file,target_file,stoptime);
127
fprintf(stderr,"chirp_put: couldn't put %s to host %s: %s\n",source_file,hostname,strerror(errno));
133
struct chirp_stream *stream;
134
char *buffer = xxmalloc(buffer_size);
135
INT64_T ractual, wactual;
137
stream = chirp_stream_open(hostname,target_file,CHIRP_STREAM_WRITE,stoptime);
139
fprintf(stderr,"chirp_put: couldn't open %s for writing: %s\n",target_file,strerror(errno));
144
ractual = full_fread(file,buffer,buffer_size);
147
debug(D_DEBUG,"waiting for more data...");
154
wactual = chirp_stream_write(stream,buffer,ractual,stoptime);
155
if(wactual!=ractual) {
156
fprintf(stderr,"chirp_put: couldn't write to %s: %s\n",target_file,strerror(errno));
160
chirp_stream_close(stream,stoptime);