version 1.70, 2009/05/05 19:35:30 |
version 1.71, 2012/10/15 21:20:05 |
|
|
extern int optind, optreset; |
extern int optind, optreset; |
int ch, i, restartit = 0; |
int ch, i, restartit = 0; |
sig_t oldintr; |
sig_t oldintr; |
char *cmd, *tp; |
char *cmd, *tp, *xargv[] = { argv[0], NULL, NULL }; |
|
const char *errstr; |
|
static int depth = 0, max_depth = 0; |
|
|
optind = optreset = 1; |
optind = optreset = 1; |
|
|
while ((ch = getopt(argc, argv, "c")) != -1) { |
if (depth) |
|
depth++; |
|
|
|
while ((ch = getopt(argc, argv, "cd:r")) != -1) { |
switch(ch) { |
switch(ch) { |
case 'c': |
case 'c': |
restartit = 1; |
restartit = 1; |
break; |
break; |
|
case 'd': |
|
max_depth = strtonum(optarg, 0, INT_MAX, &errstr); |
|
if (errstr != NULL) { |
|
fprintf(ttyout, "bad depth value, %s: %s\n", |
|
errstr, optarg); |
|
code = -1; |
|
return; |
|
} |
|
break; |
|
case 'r': |
|
depth = 1; |
|
break; |
default: |
default: |
goto usage; |
goto usage; |
} |
} |
|
|
|
|
if (argc - optind < 1 && !another(&argc, &argv, "local-files")) { |
if (argc - optind < 1 && !another(&argc, &argv, "local-files")) { |
usage: |
usage: |
fprintf(ttyout, "usage: %s [-c] local-files\n", argv[0]); |
fprintf(ttyout, "usage: %s [-cr] [-d depth] local-files\n", |
|
argv[0]); |
code = -1; |
code = -1; |
return; |
return; |
} |
} |
|
|
mflag = 0; |
mflag = 0; |
return; |
return; |
} |
} |
|
|
for (i = 1; i < argc; i++) { |
for (i = 1; i < argc; i++) { |
char **cpp; |
char **cpp; |
glob_t gl; |
glob_t gl; |
int flags; |
int flags; |
|
|
|
/* Copy files without word expansion */ |
if (!doglob) { |
if (!doglob) { |
if (mflag && confirm(argv[0], argv[i])) { |
if (mflag && confirm(argv[0], argv[i])) { |
tp = (ntflag) ? dotrans(argv[i]) : argv[i]; |
tp = (ntflag) ? dotrans(argv[i]) : argv[i]; |
|
|
continue; |
continue; |
} |
} |
|
|
|
/* expanding file names */ |
memset(&gl, 0, sizeof(gl)); |
memset(&gl, 0, sizeof(gl)); |
flags = GLOB_BRACE|GLOB_NOCHECK|GLOB_QUOTE|GLOB_TILDE; |
flags = GLOB_BRACE|GLOB_NOCHECK|GLOB_QUOTE|GLOB_TILDE; |
if (glob(argv[i], flags, NULL, &gl) || gl.gl_pathc == 0) { |
if (glob(argv[i], flags, NULL, &gl) || gl.gl_pathc == 0) { |
|
|
globfree(&gl); |
globfree(&gl); |
continue; |
continue; |
} |
} |
|
|
|
/* traverse all expanded file names */ |
for (cpp = gl.gl_pathv; cpp && *cpp != NULL; cpp++) { |
for (cpp = gl.gl_pathv; cpp && *cpp != NULL; cpp++) { |
if (mflag && confirm(argv[0], *cpp)) { |
struct stat filestat; |
tp = (ntflag) ? dotrans(*cpp) : *cpp; |
|
tp = (mapflag) ? domap(tp) : tp; |
|
if (restartit == 1) { |
|
off_t ret; |
|
|
|
if (curtype != type) |
if (!mflag) |
changetype(type, 0); |
continue; |
ret = remotesize(tp, 0); |
if (stat(*cpp, &filestat) != 0) { |
restart_point = (ret < 0) ? 0 : ret; |
warn("local: %s", *cpp); |
|
continue; |
|
} |
|
if (S_ISDIR(filestat.st_mode) && depth == max_depth) |
|
continue; |
|
if (!confirm(argv[0], *cpp)) |
|
continue; |
|
|
|
/* |
|
* If file is a directory then create a new one |
|
* at the remote machine. |
|
*/ |
|
if (S_ISDIR(filestat.st_mode)) { |
|
xargv[1] = *cpp; |
|
makedir(2, xargv); |
|
cd(2, xargv); |
|
if (dirchange != 1) { |
|
warnx("remote: %s", *cpp); |
|
continue; |
} |
} |
cmd = restartit ? "APPE" : ((sunique) ? |
|
"STOU" : "STOR"); |
if (chdir(*cpp) != 0) { |
sendrequest(cmd, *cpp, tp, |
warn("local: %s", *cpp); |
*cpp != tp || !interactive); |
goto out; |
restart_point = 0; |
|
if (!mflag && fromatty) { |
|
if (confirm(argv[0], NULL)) |
|
mflag = 1; |
|
} |
} |
|
|
|
/* Copy the whole directory recursively. */ |
|
xargv[1] = "*"; |
|
mput(2, xargv); |
|
|
|
if (chdir("..") != 0) { |
|
mflag = 0; |
|
warn("local: %s", *cpp); |
|
goto out; |
|
} |
|
|
|
out: |
|
xargv[1] = ".."; |
|
cd(2, xargv); |
|
if (dirchange != 1) { |
|
warnx("remote: %s", *cpp); |
|
mflag = 0; |
|
} |
|
continue; |
} |
} |
|
|
|
tp = (ntflag) ? dotrans(*cpp) : *cpp; |
|
tp = (mapflag) ? domap(tp) : tp; |
|
if (restartit == 1) { |
|
off_t ret; |
|
|
|
if (curtype != type) |
|
changetype(type, 0); |
|
ret = remotesize(tp, 0); |
|
restart_point = (ret < 0) ? 0 : ret; |
|
} |
|
cmd = restartit ? "APPE" : ((sunique) ? |
|
"STOU" : "STOR"); |
|
sendrequest(cmd, *cpp, tp, |
|
*cpp != tp || !interactive); |
|
restart_point = 0; |
|
if (!mflag && fromatty) { |
|
if (confirm(argv[0], NULL)) |
|
mflag = 1; |
|
} |
} |
} |
globfree(&gl); |
globfree(&gl); |
} |
} |
|
|
(void)signal(SIGINT, oldintr); |
(void)signal(SIGINT, oldintr); |
mflag = 0; |
|
|
if (depth) |
|
depth--; |
|
if (depth == 0 || mflag == 0) |
|
depth = max_depth = mflag = 0; |
} |
} |
|
|
void |
void |