-
Notifications
You must be signed in to change notification settings - Fork 138
Description
I was having a problem with scp hanging copying files to Windows (using the Windows-provided Windows 10 OpenSSH server on the remote). After a number of hours of debugging I have discovered that the problem is quoting of the path.
If I write to a Windows-form path like C:\foo\bar\myfile then the scp put() function hangs either forever, or until the timeout if you specify one. If I write to a path using UNIX slashes like C:/foo/bar/myfile then it works fine.
It appears that the default sanitize function is causing this, by wrapping the filename in single quotes if it contains characters which are special to POSIX systems, such as backslash. If I replace the sanitize with a method that simply returns a double-quoted string always then it works fine:
def winsan(pth):
return '"'+pth+'"'
with scp.SCPClient(..., sanitize=winsan) as con:
con.put(src, 'C:\\foo\\bar')
However I realize that using double-quotes on POSIX systems is much more complicated than using single quotes, and the results likely won't be portable anyway in some situations (if the path contains double-quotes for example).
I'm not exactly sure if there's any actual fix that can be made in scp itself here, but it seems like this might at least be worth a mention in the README etc. to hopefully save other people the above-mentioned hours.