scp from remote Linux to local Windows with spaces in local path
To push a file from a Linux terminal to a Windows system, the following two examples work just fine.
scp /home/user.name/file.html [email protected]:/C:/Users/user.name/test_folder/file.html
scp /home/user.name/file.html [email protected]:"/C:/Users/user.name/test_folder/file.html"
I need to do this where the local folder has spaces and I cannot change the name,
say /C:/Users/user.name/test folder/
All of the following fail with the message scp: ambiguous target
scp /home/user.name/file.html [email protected]:"/C:/Users/user.name/test folder/file.html"
scp /home/user.name/file.html [email protected]:"/C:/Users/user.name/test\ folder/file.html"
scp /home/user.name/file.html [email protected]:"'/C:/Users/user.name/test\ folder/file.html'"
scp /home/user.name/file.html [email protected]:"/C:/Users/user.name/test\\ folder/file.html"
scp /home/user.name/file.html [email protected]:"'/C:/Users/user.name/test\\ folder/file.html'"
scp /home/user.name/file.html [email protected]:"/C:/Users/user.name/test\\\ folder/file.html"
scp /home/user.name/file.html [email protected]:"'/C:/Users/user.name/test\\\ folder/file.html'"
How do I get this to work?
Solution 1:
-
Try using
quotes '
orDouble quotes "
around complete argument.As suggested by @dirkt in comments Quoting the complete path argument for the ssh host should do the work. That makes your command like this :
scp /home/user.name/file.html '[email protected]:/C:/Users/user.name/test folder/'
-
Use
escape sequence for space
in between name of folder.You can use
\
(backslash with a space) that is escape sequence for a space. That makes your command like this :scp /home/user.name/file.html '[email protected]:/C:/Users/user.name/test\ folder/'
Notice the
\
with a space in betweentest
&folder
that makes ittest\ folder
. -
It maybe the case that you
need to escape twice
as It is escaped first locally and then on the remote end. In that case you can write like this :-
"'complete argument'"
inside quotes within double quotes like this :"'[email protected]:/C:/Users/user.name/test folder/'"
OR
-
Escape spaces and quote complete argument like this :
'[email protected]:/C:/Users/user.name/test\ folder/'
OR
-
Escape twice directly using escape sequence like this
[email protected]:/C:/Users/user.name/test\\ folder/
-
Feel free to add-in more details.
Solution 2:
Tried all the options above to scp from CentOS client to Windows 7 (SP1), but without success.
This one worked for me though:
$ scp /tmp/lala 'win7@<IP>:"/Users/win7/Documents/TestComplete 14 Projects"'