Search code examples
command-lineescapingsftpfile-transferscp

Download file to Windows PC from a remote Linux PC where the path to the file contains spaces


I have tried using both scp and sftp, in both Powershell and at the windows commandline. I also tried doing this from Windows 10 Linux Subsystem but nothing has worked so far.

Part of the problem seems to be escaping the remote Linux file path, which has a space in it. I can't use "\" as this is interpreted incorrectly by Windows. I have also tried using ^ and ` instead and using single and/or double quotes.

Using Windows cmd:

C:\Users\psnow>scp dad@192.168.1.4:"//home/naomi/Documents/School Work/Misc/schedule.pdf" c:\Users\psnow\Downloads\schedule.pdf
dad@192.168.1.4's password:
scp: //home/naomi/Documents/School: No such file or directory
scp: Work/Misc/schedule.pdf: No such file or directory

This one looked like it got past the space issue, but then came up with this weird error?

C:\Users\psnow>scp dad@192.168.1.4:"'//home/naomi/Documents/School Work/Misc/schedule.pdf'" c:\Users\psnow\Downloads\schedule.pdf
dad@192.168.1.4's password:
protocol error: filename does not match request

Using Linux Subsystem and Powershell both have similar responses.

All of the tutorials I've found on the subject use simplistic examples without spaces. I'd be happy to use sftp also, but I'm having similar issues with that too.


Solution

  • Have you tried escaping without quotes?

    C:\Users\psnow>scp dad@192.168.1.4://home/naomi/Documents/School\ Work/Misc/schedule.pdf c:\Users\psnow\Downloads\schedule.pdf
    

    Or, googling shows me that you have to escape with four backslashes inside ""

    C:\Users\psnow>scp dad@192.168.1.4:"//home/naomi/Documents/School\\\\ Work/Misc/schedule.pdf" c:\Users\psnow\Downloads\schedule.pdf
    

    Unfortunately I cannot try this right now.. hope one of them works for you

    Update: Just tried and none of above worked for me

    What worked for me:

    C:\Users\psnow>scp dad@192.168.1.4:"//home/naomi/Documents/'School Work'/Misc/schedule.pdf" c:\Users\psnow\Downloads\schedule.pdf