Open vtyw opened 4 years ago
I'm not sure I understand the slash issue, does opening "V:/test.txt" not work on Windows, same as "V:\test.txt"?
Escaping spaces was implemented (#9) and is tested for, so if you're seeing problems there it might be another Windows-specific problem?
I'm not sure I understand the slash issue, does opening "V:/test.txt" not work on Windows, same as "V:\test.txt"?
I've just realized that scp expects you to use "/" as the path separator even when copying from a Windows machine. So get("V:/test.txt") does work, whereas get("V:\test.txt") does not and gives the misleading error that 'V:/test.txt' doesn't exist.
As for spaces, if I'm trying to copy "V:\test 1.txt", I've tried:
There is clearly something weird going on with the formatting of the output message, though that may be a separate issue to whether escaping works.
The second version is expected to work (get('"V:/sample 1.txt"')
). Are you sure the file exist? Is it "sample" or "test"?
Also all of this might depend on your server implementation (if using cygwin, you might need /cygdrive/v/sample 1.txt
, etc)
Pardon my inconsistency with filename above. That aside, I am sure the file exists. For comparison I can copy it without problem using paramiko.SFTPClient:
sftp.get('V:/sample 1.txt', 'sample 1.txt') # Works
scp.get('"V:/sample 1.txt"') # scp.SCPException
I also just discovered that quoting doesn't seem to be acceptable in the first place, with or without spaces in the filename.
scp.get('V:/test.txt') # Works
scp.get('"V:/test.txt"') # SCPException
scp.get("'V:/test.txt'") # SCPException
I fear I know what is happening.
Do you mind trying the following:
scp.sanitize = lambda x: x
scp.get('V:/sample^ 1.txt', 's.txt')
>>> scp.sanitize
<function _sh_quote at 0x7f86bb527400>
>>> scp.sanitize = lambda x: x
>>> scp.get('V:/sample^ 1.txt', 's.txt')
scp.SCPException: scp: V:/sample: No such file or directory
>>> scp.get('V:/sample 1.txt', 's.txt')
scp.SCPException: scp: V:/sample: No such file or directory
>>> scp.get('"V:/sample 1.txt"') # Worked!
Ok well what is apparent is:
sanitize
constructor argument is meant for UNIX. You will have to provide your own if you know the server is Windows.I could change the _sh_quote
function to use double quotes instead of single quotes, which would make more filename patterns work on Windows (maybe? Does Windows have single quotes?), but that would still be accidental as those are different shells with different rules, and some characters would still cause breakage.
My understanding is that Windows command-line only supports double-quoted strings.
I will replace the current _sh_quote
with this version then, which should improve the situation. I guess I have to revisit reprozip's quoting functions...
When trying to get a file such as
V:\test.txt
from a Windows host, this exception occurs:It looks like backslashes get converted to forward slashes which would make it impossible to copy anything from a Windows server to a Linux client. I also note that spaces in filenames passed to scp.SCPClient.get are treated as if scp is requesting multiple separate files, so it seems like there is both shell interpretation going on AND some unwarranted Linux-style translation of the path happening on a Linux client.