version 1.204, 2020/10/29 02:52:43 |
version 1.205, 2020/12/04 02:41:10 |
|
|
return (xstrdup(path)); |
return (xstrdup(path)); |
} |
} |
|
|
static char * |
|
make_absolute(char *p, const char *pwd) |
|
{ |
|
char *abs_str; |
|
|
|
/* Derelativise */ |
|
if (p && !path_absolute(p)) { |
|
abs_str = path_append(pwd, p); |
|
free(p); |
|
return(abs_str); |
|
} else |
|
return(p); |
|
} |
|
|
|
static int |
static int |
parse_getput_flags(const char *cmd, char **argv, int argc, |
parse_getput_flags(const char *cmd, char **argv, int argc, |
int *aflag, int *fflag, int *pflag, int *rflag) |
int *aflag, int *fflag, int *pflag, int *rflag) |
|
|
} |
} |
|
|
static int |
static int |
is_dir(const char *path) |
|
{ |
|
struct stat sb; |
|
|
|
/* XXX: report errors? */ |
|
if (stat(path, &sb) == -1) |
|
return(0); |
|
|
|
return(S_ISDIR(sb.st_mode)); |
|
} |
|
|
|
static int |
|
remote_is_dir(struct sftp_conn *conn, const char *path) |
|
{ |
|
Attrib *a; |
|
|
|
/* XXX: report errors? */ |
|
if ((a = do_stat(conn, path, 1)) == NULL) |
|
return(0); |
|
if (!(a->flags & SSH2_FILEXFER_ATTR_PERMISSIONS)) |
|
return(0); |
|
return(S_ISDIR(a->perm)); |
|
} |
|
|
|
/* Check whether path returned from glob(..., GLOB_MARK, ...) is a directory */ |
|
static int |
|
pathname_is_dir(const char *pathname) |
|
{ |
|
size_t l = strlen(pathname); |
|
|
|
return l > 0 && pathname[l - 1] == '/'; |
|
} |
|
|
|
static int |
|
process_get(struct sftp_conn *conn, const char *src, const char *dst, |
process_get(struct sftp_conn *conn, const char *src, const char *dst, |
const char *pwd, int pflag, int rflag, int resume, int fflag) |
const char *pwd, int pflag, int rflag, int resume, int fflag) |
{ |
{ |
|
|
* If multiple matches then dst must be a directory or |
* If multiple matches then dst must be a directory or |
* unspecified. |
* unspecified. |
*/ |
*/ |
if (g.gl_matchc > 1 && dst != NULL && !is_dir(dst)) { |
if (g.gl_matchc > 1 && dst != NULL && !local_is_dir(dst)) { |
error("Multiple source paths, but destination " |
error("Multiple source paths, but destination " |
"\"%s\" is not a directory", dst); |
"\"%s\" is not a directory", dst); |
err = -1; |
err = -1; |
|
|
} |
} |
|
|
if (g.gl_matchc == 1 && dst) { |
if (g.gl_matchc == 1 && dst) { |
if (is_dir(dst)) { |
if (local_is_dir(dst)) { |
abs_dst = path_append(dst, filename); |
abs_dst = path_append(dst, filename); |
} else { |
} else { |
abs_dst = xstrdup(dst); |
abs_dst = xstrdup(dst); |
|
|
else if (!quiet && !resume) |
else if (!quiet && !resume) |
mprintf("Fetching %s to %s\n", |
mprintf("Fetching %s to %s\n", |
g.gl_pathv[i], abs_dst); |
g.gl_pathv[i], abs_dst); |
if (pathname_is_dir(g.gl_pathv[i]) && (rflag || global_rflag)) { |
if (globpath_is_dir(g.gl_pathv[i]) && (rflag || global_rflag)) { |
if (download_dir(conn, g.gl_pathv[i], abs_dst, NULL, |
if (download_dir(conn, g.gl_pathv[i], abs_dst, NULL, |
pflag || global_pflag, 1, resume, |
pflag || global_pflag, 1, resume, |
fflag || global_fflag) == -1) |
fflag || global_fflag) == -1) |
|
|
else if (!quiet && !resume) |
else if (!quiet && !resume) |
mprintf("Uploading %s to %s\n", |
mprintf("Uploading %s to %s\n", |
g.gl_pathv[i], abs_dst); |
g.gl_pathv[i], abs_dst); |
if (pathname_is_dir(g.gl_pathv[i]) && (rflag || global_rflag)) { |
if (globpath_is_dir(g.gl_pathv[i]) && (rflag || global_rflag)) { |
if (upload_dir(conn, g.gl_pathv[i], abs_dst, |
if (upload_dir(conn, g.gl_pathv[i], abs_dst, |
pflag || global_pflag, 1, resume, |
pflag || global_pflag, 1, resume, |
fflag || global_fflag) == -1) |
fflag || global_fflag) == -1) |