Sunday 6 May 2018

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 user.name@local.ip.num:/C:/Users/user.name/test_folder/file.html

scp /home/user.name/file.html user.name@local.ip.num:"/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 user.name@local.ip.num:"/C:/Users/user.name/test folder/file.html"

scp /home/user.name/file.html user.name@local.ip.num:"/C:/Users/user.name/test\ folder/file.html"

scp /home/user.name/file.html user.name@local.ip.num:"'/C:/Users/user.name/test\ folder/file.html'"

scp /home/user.name/file.html user.name@local.ip.num:"/C:/Users/user.name/test\\ folder/file.html"

scp /home/user.name/file.html user.name@local.ip.num:"'/C:/Users/user.name/test\\ folder/file.html'"

scp /home/user.name/file.html user.name@local.ip.num:"/C:/Users/user.name/test\\\ folder/file.html"

scp /home/user.name/file.html user.name@local.ip.num:"'/C:/Users/user.name/test\\\ folder/file.html'"

How do I get this to work?



Answer





  • Try using quotes ' or Double 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 'user.name@local.ip.num:/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 'user.name@local.ip.num:/C:/Users/user.name/test\ folder/'

    Notice the \ with a space in between test & folder that makes it test\ 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 :




    1. "'complete argument'" inside quotes within double quotes like this :


      "'user.name@local.ip.num:/C:/Users/user.name/test folder/'"

      OR




    2. Escape spaces and quote complete argument like this :


      'user.name@local.ip.num:/C:/Users/user.name/test\ folder/'

      OR




    3. Escape twice directly using escape sequence like this


      user.name@local.ip.num:/C:/Users/user.name/test\\ folder/




Feel free to add-in more details.


No comments:

Post a Comment

Where does Skype save my contact's avatars in Linux?

I'm using Skype on Linux. Where can I find images cached by skype of my contact's avatars? Answer I wanted to get those Skype avat...