From dcf8495c8d658ff9981c76cb0ea8e3a58f8d87d9 Mon Sep 17 00:00:00 2001 From: simon Date: Wed, 12 Sep 2001 20:16:45 +0000 Subject: [PATCH] PSFTP: when choosing a default destination filename for `get' and `put', it makes more sense to pick the _basename_ of the source rather than use the whole path - particularly when the latter might cause us to try to use a DOS pathname like `f:\stuff' in a Unix (or worse, such as VMS!) file system. git-svn-id: svn://svn.tartarus.org/sgt/putty@1265 cda61777-01e9-0310-a592-d414129be87e --- psftp.c | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/psftp.c b/psftp.c index 137320b8..4fe7383d 100644 --- a/psftp.c +++ b/psftp.c @@ -130,6 +130,30 @@ char *canonify(char *name) } } +/* + * Return a pointer to the portion of str that comes after the last + * slash (or backslash or colon, if `local' is TRUE). + */ +static char *stripslashes(char *str, int local) +{ + char *p; + + if (local) { + p = strchr(str, ':'); + if (p) str = p+1; + } + + p = strrchr(str, '/'); + if (p) str = p+1; + + if (local) { + p = strrchr(str, '\\'); + if (p) str = p+1; + } + + return str; +} + /* ---------------------------------------------------------------------- * Actual sftp commands. */ @@ -307,7 +331,8 @@ int sftp_general_get(struct sftp_command *cmd, int restart) printf("%s: %s\n", cmd->words[1], fxp_error()); return 0; } - outfname = (cmd->nwords == 2 ? cmd->words[1] : cmd->words[2]); + outfname = (cmd->nwords == 2 ? + stripslashes(cmd->words[1], 0) : cmd->words[2]); fh = fxp_open(fname, SSH_FXF_READ); if (!fh) { @@ -406,7 +431,8 @@ int sftp_general_put(struct sftp_command *cmd, int restart) } fname = cmd->words[1]; - origoutfname = (cmd->nwords == 2 ? cmd->words[1] : cmd->words[2]); + origoutfname = (cmd->nwords == 2 ? + stripslashes(cmd->words[1], 1) : cmd->words[2]); outfname = canonify(origoutfname); if (!outfname) { printf("%s: %s\n", origoutfname, fxp_error()); -- 2.11.0