2024-01-12 12:55:32 +00:00
|
|
|
diff --git a/scp.c b/scp.c
|
|
|
|
--- a/scp.c (revision 8241b9c0529228b4b86d88b1a6076fb9f97e4a99)
|
|
|
|
+++ b/scp.c (date 1703111453316)
|
|
|
|
@@ -1372,7 +1372,7 @@
|
|
|
|
|
2022-08-10 13:08:21 +00:00
|
|
|
if (src_is_dir && iamrecursive) {
|
2024-01-12 12:55:32 +00:00
|
|
|
if (sftp_upload_dir(conn, src, abs_dst, pflag,
|
2023-04-27 15:52:26 +00:00
|
|
|
- SFTP_PROGRESS_ONLY, 0, 0, 1, 1) != 0) {
|
|
|
|
+ SFTP_PROGRESS_ONLY, 0, 0, 1, 1, 1) != 0) {
|
2024-01-12 12:55:32 +00:00
|
|
|
error("failed to upload directory %s to %s", src, targ);
|
|
|
|
errs = 1;
|
|
|
|
}
|
|
|
|
diff --git a/sftp-client.c b/sftp-client.c
|
|
|
|
--- a/sftp-client.c (revision 8241b9c0529228b4b86d88b1a6076fb9f97e4a99)
|
|
|
|
+++ b/sftp-client.c (date 1703169614263)
|
|
|
|
@@ -1003,7 +1003,7 @@
|
|
|
|
|
2022-08-10 13:08:21 +00:00
|
|
|
/* Implements both the realpath and expand-path operations */
|
|
|
|
static char *
|
2024-01-12 12:55:32 +00:00
|
|
|
-sftp_realpath_expand(struct sftp_conn *conn, const char *path, int expand)
|
|
|
|
+sftp_realpath_expand(struct sftp_conn *conn, const char *path, int expand, int create_dir)
|
2022-08-10 13:08:21 +00:00
|
|
|
{
|
|
|
|
struct sshbuf *msg;
|
|
|
|
u_int expected_id, count, id;
|
2024-01-12 12:55:32 +00:00
|
|
|
@@ -1049,11 +1049,43 @@
|
2022-08-11 12:54:03 +00:00
|
|
|
if ((r = sshbuf_get_u32(msg, &status)) != 0 ||
|
|
|
|
(r = sshbuf_get_cstring(msg, &errmsg, NULL)) != 0)
|
2022-08-10 13:08:21 +00:00
|
|
|
fatal_fr(r, "parse status");
|
2022-08-11 12:54:03 +00:00
|
|
|
- error("%s %s: %s", expand ? "expand" : "realpath",
|
|
|
|
- path, *errmsg == '\0' ? fx2txt(status) : errmsg);
|
|
|
|
- free(errmsg);
|
2022-08-10 13:08:21 +00:00
|
|
|
- sshbuf_free(msg);
|
|
|
|
- return NULL;
|
|
|
|
+ if ((status == SSH2_FX_NO_SUCH_FILE) && create_dir) {
|
|
|
|
+ memset(&a, '\0', sizeof(a));
|
2024-01-12 12:55:32 +00:00
|
|
|
+ if ((r = sftp_mkdir(conn, path, &a, 0)) != 0) {
|
2022-08-10 13:08:21 +00:00
|
|
|
+ sshbuf_free(msg);
|
|
|
|
+ return NULL;
|
|
|
|
+ }
|
2022-08-11 12:54:03 +00:00
|
|
|
+ debug2("Sending SSH2_FXP_REALPATH \"%s\" - create dir", path);
|
2022-08-10 13:08:21 +00:00
|
|
|
+ send_string_request(conn, id, SSH2_FXP_REALPATH,
|
|
|
|
+ path, strlen(path));
|
|
|
|
+
|
|
|
|
+ get_msg(conn, msg);
|
|
|
|
+ if ((r = sshbuf_get_u8(msg, &type)) != 0 ||
|
2022-08-11 12:54:03 +00:00
|
|
|
+ (r = sshbuf_get_u32(msg, &id)) != 0)
|
2022-08-10 13:08:21 +00:00
|
|
|
+ fatal_fr(r, "parse");
|
|
|
|
+
|
|
|
|
+ if (id != expected_id)
|
|
|
|
+ fatal("ID mismatch (%u != %u)", id, expected_id);
|
|
|
|
+
|
|
|
|
+ if (type == SSH2_FXP_STATUS) {
|
2022-08-11 12:54:03 +00:00
|
|
|
+ free(errmsg);
|
2022-08-10 13:08:21 +00:00
|
|
|
+
|
2022-08-11 12:54:03 +00:00
|
|
|
+ if ((r = sshbuf_get_u32(msg, &status)) != 0 ||
|
|
|
|
+ (r = sshbuf_get_cstring(msg, &errmsg, NULL)) != 0)
|
2022-08-10 13:08:21 +00:00
|
|
|
+ fatal_fr(r, "parse status");
|
2022-08-11 12:54:03 +00:00
|
|
|
+ error("%s %s: %s", expand ? "expand" : "realpath",
|
|
|
|
+ path, *errmsg == '\0' ? fx2txt(status) : errmsg);
|
|
|
|
+ free(errmsg);
|
2022-08-10 13:08:21 +00:00
|
|
|
+ sshbuf_free(msg);
|
|
|
|
+ return NULL;
|
|
|
|
+ }
|
|
|
|
+ } else {
|
2022-08-11 12:54:03 +00:00
|
|
|
+ error("%s %s: %s", expand ? "expand" : "realpath",
|
|
|
|
+ path, *errmsg == '\0' ? fx2txt(status) : errmsg);
|
|
|
|
+ free(errmsg);
|
2022-08-10 13:08:21 +00:00
|
|
|
+ sshbuf_free(msg);
|
|
|
|
+ return NULL;
|
|
|
|
+ }
|
|
|
|
} else if (type != SSH2_FXP_NAME)
|
|
|
|
fatal("Expected SSH2_FXP_NAME(%u) packet, got %u",
|
|
|
|
SSH2_FXP_NAME, type);
|
2024-01-12 12:55:32 +00:00
|
|
|
@@ -1078,9 +1110,9 @@
|
2022-08-10 13:08:21 +00:00
|
|
|
}
|
2024-01-12 12:55:32 +00:00
|
|
|
|
2022-08-10 13:08:21 +00:00
|
|
|
char *
|
2024-01-12 12:55:32 +00:00
|
|
|
-sftp_realpath(struct sftp_conn *conn, const char *path)
|
|
|
|
+sftp_realpath(struct sftp_conn *conn, const char *path, int create_dir)
|
2022-08-10 13:08:21 +00:00
|
|
|
{
|
2024-01-12 12:55:32 +00:00
|
|
|
- return sftp_realpath_expand(conn, path, 0);
|
|
|
|
+ return sftp_realpath_expand(conn, path, 0, create_dir);
|
2022-08-10 13:08:21 +00:00
|
|
|
}
|
2024-01-12 12:55:32 +00:00
|
|
|
|
2022-08-10 13:08:21 +00:00
|
|
|
int
|
2024-01-12 12:55:32 +00:00
|
|
|
@@ -1094,9 +1126,9 @@
|
2022-08-10 13:08:21 +00:00
|
|
|
{
|
2024-01-12 12:55:32 +00:00
|
|
|
if (!sftp_can_expand_path(conn)) {
|
2022-08-10 13:08:21 +00:00
|
|
|
debug3_f("no server support, fallback to realpath");
|
2024-01-12 12:55:32 +00:00
|
|
|
- return sftp_realpath_expand(conn, path, 0);
|
|
|
|
+ return sftp_realpath_expand(conn, path, 0, 0);
|
2022-08-10 13:08:21 +00:00
|
|
|
}
|
2024-01-12 12:55:32 +00:00
|
|
|
- return sftp_realpath_expand(conn, path, 1);
|
|
|
|
+ return sftp_realpath_expand(conn, path, 1, 0);
|
2022-08-10 13:08:21 +00:00
|
|
|
}
|
2024-01-12 12:55:32 +00:00
|
|
|
|
2022-08-10 13:08:21 +00:00
|
|
|
int
|
2024-01-12 12:55:32 +00:00
|
|
|
@@ -2016,7 +2048,7 @@
|
2022-08-10 13:08:21 +00:00
|
|
|
char *src_canon;
|
|
|
|
int ret;
|
2024-01-12 12:55:32 +00:00
|
|
|
|
|
|
|
- if ((src_canon = sftp_realpath(conn, src)) == NULL) {
|
|
|
|
+ if ((src_canon = sftp_realpath(conn, src, 0)) == NULL) {
|
|
|
|
error("download \"%s\": path canonicalization failed", src);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
@@ -2365,12 +2397,12 @@
|
2022-08-10 13:08:21 +00:00
|
|
|
int
|
2024-01-12 12:55:32 +00:00
|
|
|
sftp_upload_dir(struct sftp_conn *conn, const char *src, const char *dst,
|
2022-08-10 13:08:21 +00:00
|
|
|
int preserve_flag, int print_flag, int resume, int fsync_flag,
|
2023-04-27 15:52:26 +00:00
|
|
|
- int follow_link_flag, int inplace_flag)
|
|
|
|
+ int follow_link_flag, int inplace_flag, int create_dir)
|
2022-08-10 13:08:21 +00:00
|
|
|
{
|
|
|
|
char *dst_canon;
|
|
|
|
int ret;
|
2024-01-12 12:55:32 +00:00
|
|
|
|
|
|
|
- if ((dst_canon = sftp_realpath(conn, dst)) == NULL) {
|
|
|
|
+ if ((dst_canon = sftp_realpath(conn, dst, create_dir)) == NULL) {
|
|
|
|
error("upload \"%s\": path canonicalization failed", dst);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
@@ -2825,7 +2857,7 @@
|
2022-08-10 13:08:21 +00:00
|
|
|
char *from_path_canon;
|
|
|
|
int ret;
|
2024-01-12 12:55:32 +00:00
|
|
|
|
|
|
|
- if ((from_path_canon = sftp_realpath(from, from_path)) == NULL) {
|
|
|
|
+ if ((from_path_canon = sftp_realpath(from, from_path, 0)) == NULL) {
|
|
|
|
error("crossload \"%s\": path canonicalization failed",
|
|
|
|
from_path);
|
|
|
|
return -1;
|
|
|
|
diff --git a/sftp-client.h b/sftp-client.h
|
|
|
|
--- a/sftp-client.h (revision 8241b9c0529228b4b86d88b1a6076fb9f97e4a99)
|
|
|
|
+++ b/sftp-client.h (date 1703111691284)
|
|
|
|
@@ -111,7 +111,7 @@
|
|
|
|
int sftp_lsetstat(struct sftp_conn *conn, const char *path, Attrib *a);
|
|
|
|
|
2022-08-10 13:08:21 +00:00
|
|
|
/* Canonicalise 'path' - caller must free result */
|
2024-01-12 12:55:32 +00:00
|
|
|
-char *sftp_realpath(struct sftp_conn *, const char *);
|
|
|
|
+char *sftp_realpath(struct sftp_conn *, const char *, int);
|
|
|
|
|
2022-08-10 13:08:21 +00:00
|
|
|
/* Canonicalisation with tilde expansion (requires server extension) */
|
2024-01-12 12:55:32 +00:00
|
|
|
char *sftp_expand_path(struct sftp_conn *, const char *);
|
|
|
|
@@ -163,7 +163,7 @@
|
2022-08-10 13:08:21 +00:00
|
|
|
* times if 'pflag' is set
|
|
|
|
*/
|
2024-01-12 12:55:32 +00:00
|
|
|
int sftp_upload_dir(struct sftp_conn *, const char *, const char *,
|
2023-04-27 15:52:26 +00:00
|
|
|
- int, int, int, int, int, int);
|
|
|
|
+ int, int, int, int, int, int, int);
|
2024-01-12 12:55:32 +00:00
|
|
|
|
2022-08-10 13:08:21 +00:00
|
|
|
/*
|
|
|
|
* Download a 'from_path' from the 'from' connection and upload it to
|
2024-01-12 12:55:32 +00:00
|
|
|
|
|
|
|
diff --git a/sftp.c b/sftp.c
|
|
|
|
--- a/sftp.c (revision 8241b9c0529228b4b86d88b1a6076fb9f97e4a99)
|
|
|
|
+++ b/sftp.c (date 1703168795365)
|
|
|
|
@@ -807,7 +807,7 @@
|
|
|
|
(rflag || global_rflag)) {
|
|
|
|
if (sftp_upload_dir(conn, g.gl_pathv[i], abs_dst,
|
2022-08-10 13:08:21 +00:00
|
|
|
pflag || global_pflag, 1, resume,
|
2023-04-27 15:52:26 +00:00
|
|
|
- fflag || global_fflag, 0, 0) == -1)
|
|
|
|
+ fflag || global_fflag, 0, 0, 0) == -1)
|
2022-08-10 13:08:21 +00:00
|
|
|
err = -1;
|
|
|
|
} else {
|
2024-01-12 12:55:32 +00:00
|
|
|
if (sftp_upload(conn, g.gl_pathv[i], abs_dst,
|
|
|
|
@@ -1642,7 +1642,7 @@
|
2022-08-10 13:08:21 +00:00
|
|
|
if (path1 == NULL || *path1 == '\0')
|
|
|
|
path1 = xstrdup(startdir);
|
2024-01-12 12:55:32 +00:00
|
|
|
path1 = sftp_make_absolute(path1, *pwd);
|
|
|
|
- if ((tmp = sftp_realpath(conn, path1)) == NULL) {
|
|
|
|
+ if ((tmp = sftp_realpath(conn, path1, 0)) == NULL) {
|
2022-08-10 13:08:21 +00:00
|
|
|
err = 1;
|
|
|
|
break;
|
|
|
|
}
|
2024-01-12 12:55:32 +00:00
|
|
|
@@ -2247,7 +2247,7 @@
|
2022-08-10 13:08:21 +00:00
|
|
|
}
|
|
|
|
#endif /* USE_LIBEDIT */
|
2024-01-12 12:55:32 +00:00
|
|
|
|
|
|
|
- if ((remote_path = sftp_realpath(conn, ".")) == NULL)
|
|
|
|
+ if ((remote_path = sftp_realpath(conn, ".", 0)) == NULL)
|
2022-08-10 13:08:21 +00:00
|
|
|
fatal("Need cwd");
|
|
|
|
startdir = xstrdup(remote_path);
|
2024-01-12 12:55:32 +00:00
|
|
|
|