Sam Hocevar
2016-Sep-20 09:20 UTC
[PATCH] Allow scp to copy files that start with a Windows drive name.
On Windows, ?scp C:/foo/bar remotehost:? will attempt to connect to a remote host ?C? and access file ?/foo/bar?. There is currently no syntax or flag to allow copying files that start with a drive name. This patch changes the behaviour (only on Cygwin) by considering that a single letter followed by a colon is a Windows drive name and thus an absolute path. This is also more consistent with the manual page that recommends to use absolute pathnames ?to avoid scp treating file names containing ?:? as host specifiers?. It is still possible to access files on a machine ?C? by using square brackets, e.g. ?scp [C]:/foo/bar remotehost:?. There are countless user reports indicating that this behaviour is desirable: - http://stackoverflow.com/q/8975798/111461 - http://serverfault.com/q/582048/73723 - http://superuser.com/q/291840/71253 - https://www.reddit.com/r/commandline/comments/371q5i - http://stackoverflow.com/q/21587036/111461 - http://askubuntu.com/q/354330/12301 - http://superuser.com/q/338075/71253 - https://ubuntuforums.org/archive/index.php/t-1131655.html - http://www.linuxquestions.org/questions/linux-newbie-8/transfer-files-from-linux-to-windows-pscp-4175530524/ --- misc.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/misc.c b/misc.c index 9421b4d..cd10287 100644 --- a/misc.c +++ b/misc.c @@ -435,6 +435,10 @@ colon(char *cp) if (*cp == ':') /* Leading colon is part of file name. */ return NULL; +#ifdef HAVE_CYGWIN + if (isalpha(*cp) && *(cp+1) == ':') /* Do not split at drive name. */ + return NULL; +#endif if (*cp == '[') flag = 1; -- 2.1.4
Scott Neugroschl
2016-Sep-20 15:35 UTC
[PATCH] Allow scp to copy files that start with a Windows drive name.
Quoth Sam: On Windows, ?scp C:/foo/bar remotehost:? will attempt to connect to a remote host ?C? and access file ?/foo/bar?. There is currently no syntax or flag to allow copying files that start with a drive name. This patch changes the behaviour (only on Cygwin) by considering that a single letter followed by a colon is a Windows drive name and thus an absolute path. This is also more consistent with the manual page that recommends to use absolute pathnames ?to avoid scp treating file names containing ?:? as host specifiers?. ----------------------- Is this really necessary? Especially since it's a Cygwin specific patch, what is wrong with simply using /cygdrive/C/foo/bar?
Cedric Blancher
2016-Sep-20 16:28 UTC
[PATCH] Allow scp to copy files that start with a Windows drive name.
It should work if you quote the ':' character with a '\' ... no need for the patch. Ced On 20 September 2016 at 17:35, Scott Neugroschl <scott_n at xypro.com> wrote:> Quoth Sam: > On Windows, ?scp C:/foo/bar remotehost:? will attempt to connect to a remote host ?C? > and access file ?/foo/bar?. There is currently no syntax or flag to allow copying files that start with a drive name. > > This patch changes the behaviour (only on Cygwin) by considering that a single letter followed by a colon is a Windows drive name and thus an absolute path. This is also more consistent with the manual page that recommends to use absolute pathnames ?to avoid scp treating file names containing ?:? as host specifiers?. > ----------------------- > > Is this really necessary? Especially since it's a Cygwin specific patch, what is wrong with simply using /cygdrive/C/foo/bar? > > > _______________________________________________ > openssh-unix-dev mailing list > openssh-unix-dev at mindrot.org > https://lists.mindrot.org/mailman/listinfo/openssh-unix-dev-- Cedric Blancher <cedric.blancher at gmail.com> [https://plus.google.com/u/0/+CedricBlancher/] Institute Pasteur
Sam Hocevar
2016-Sep-20 16:56 UTC
[PATCH] Allow scp to copy files that start with a Windows drive name.
On Tue, Sep 20, 2016, Scott Neugroschl wrote:> This patch changes the behaviour (only on Cygwin) by considering that a > single letter followed by a colon is a Windows drive name and thus an > absolute path. This is also more consistent with the manual page that > recommends to use absolute pathnames ?to avoid scp treating file names > containing ?:? as host specifiers?. > > ----------------------- > > Is this really necessary? Especially since it's a Cygwin specific patch, what is wrong with simply using /cygdrive/C/foo/bar?The patch uses HAVE_CYGWIN but is not Cygwin-specific, it also applies to MSYS2 which is a modern Cygwin fork and does not have /cygdrive/C/ (it uses /c/ directly instead). Also an interactive user may immediately correct the error by changing the path to a Unix-like one instead, but sometimes the arguments are not user-controlled, or scp is used together with non-Cygwin applications, or is embedded into a larger script that expects scp to behave as documented for absolute paths. From a least surprise perspective, I believe the correct place to fix this is indeed in scp. Finally, drives in /cygdrive/ (or in MSYS2 /c/) are not immediately accessible; a newly mounted network device or thumb drive will fail to appear unless the terminal is closed and a new one is opened. If the shell is a child of sshd.exe it would even require a restart of the SSH server. Regards, -- Sam.
Sam Hocevar
2016-Nov-23 00:09 UTC
[PATCH] Allow scp to copy files that start with a Windows drive name.
On Tue, Sep 20, 2016, Sam Hocevar wrote:> On Windows, ?scp C:/foo/bar remotehost:? will attempt to connect to > a remote host ?C? and access file ?/foo/bar?. There is currently no > syntax or flag to allow copying files that start with a drive name.Any comments on this patch maybe? Right now it is impossible to do ?scp 'C:\foo\bar' remotehost:? on Windows. Regards, -- Sam.
Seemingly Similar Threads
- Legacy option for key length?
- RT/Linux SCHED_RR/_FIXED to combat latency?
- hackers celebrate this day: openssh drops security! was: Re: heads up: tcpwrappers support going away
- RT/Linux SCHED_RR/_FIXED to combat latency?
- Evaluating a port to RTEMS (embedded OS with single address space and no processes)