How to use cygwin with sshd to scp a file from the Program Files (x86) directory on another machine?

StackOverflow https://stackoverflow.com/questions/20790395

  •  21-09-2022
  •  | 
  •  

Question

I have a Linux machine and 2 Windows machines. Each Windows machine contains cygwin with an sshd daemon. The Linux machine is the main one I'm using. On the first Windows machine which is XP, I have a file on there that I want to compare with a file on the second Windows machine which is Windows 7.

My thinking is that once I ssh into the XP machine, I should easily be able to use the scp command to grab the file on the Windows 7 machine and then run a diff to compare the 2 files but it first gets tripped up on the spaces within "Program Files" and after using \ to escape those, it gets tripped up on the parenthesis.

Escaped spaces

$ scp root@10.10.10.10:/cygdrive/c/Program\ Files\ (x86)/myfile.xml .
-bash: syntax error near unexpected token `('

Escaped slashes

$ scp root@10.10.10.10:/cygdrive/c/Program\ Files\ \(x86\)/myfile.xml .
root@10.10.10.10's password: 
bash: -c: line 0: syntax error near unexpected token `('
bash: -c: line 0: `scp -f /cygdrive/c/Program Files (x86)/myfile.xml'

Used a variable

$ scpfile="/cygdrive/c/Program Files (x86)/myfile.xml"
$ scp root@10.10.10.10:$scpfile .
root@10.10.10.10's password: 
scp: /cygdrive/c/Program: No such file or directory
cp: cannot stat `Files': No such file or directory
cp: cannot stat `(x86)/myfile.xml': No such file or directory

I also tried using a variable with escape slashes but no luck.

If I move myfile.xml to /cygdrive/c/ and then scp it, it will work fine. How do I scp files that are in a directory that contain parenthesis using cygwin's scp?

Was it helpful?

Solution

If you create a soft link to the Program Files (x86) directory and make the name without spaces or parentheses, then you can use that directory in conjunction with scp.

On Cygwin (10.10.10.10)

cd c:
ln -s "Program Files (x86)" PF86

On Linux (home computer that you're running scp on)

scp root@10.10.10.10:/cygdrive/c/PF86/myfile.xml .

And it works

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top