4

I use scp to transfer files from my android to my MacBook which works like a charm. But I have a folder called John's folder on my MacBook so when I attempt to copy a file inside that directory like scp macbook@192.168.0.3:/Users/macbook/desktop/John\'s\ folder/file storage/folder

It throws back an error

unexpected EOF error while looking for matching \`’\`

and

unexpected end of file

How do I resolve this?

1
  • Try using double quotes instead: scp "macbook@192.168.0.3:/Users/macbook/desktop/John's folder/file storage/folder". But also just don't give files/directories such crazy names. – jesse_b Apr 19 '18 at 18:23
3

This is interesting. The other answers that I'm seeing are telling you to swap your escaped quote and escaped space for a quoted string. Actually they're equivalent so you'll see no change (a\'\ b is the same to the shell as "a' b").

The problem here lies in the way that scp on the remote system interprets the command line that it's being given.

As an example, this would work:

scp John\'s\ folder/file localhost:/tmp/dst

But this would fail:

scp localhost:/tmp/src/John\'s\ folder/file /tmp/dst

(I've used localhost for the example; you should use user@host for your situation.)

If you include the -v (verbose) flag on scp you can see exactly what's going on that gives rise to the failure:

debug1: Sending command: scp -v -f /tmp/src/John's folder/file
bash: -c: line 0: unexpected EOF while looking for matching `''
bash: -c: line 1: syntax error: unexpected end of file

The unfortunate solution here is that you need to escape special characters (including whitespace) twice - once for the local shell, and once for the remote shell:

scp localhost:"/tmp/src/John\'s\ folder/file" /tmp/dst
0

SCP needs to include one entire parameter in quotations. 2 different answers before me are partially right, but the correct answer is

scp "macbook@192.168.0.3:/Users/macbook/desktop/John's folder/file" storage/folder

Notice that the first parameter is wrapped in quotes, but not the second - if both were wrapped in a single instance of quotations as one comments suggests, the /bin/scp would invoke this as a single parameter, and be expecting another parameter after that.

scp "macbook@192.168.0.3:/Users/macbook/desktop/John's folder/file storage/folder" will be read as a single parameter. Even though there is a space there, the double quotes escape that.

Finally, putting quotations in the middle of a parameter like scp macbook@192.168.0.3:"/Users/macbook/desktop/John's folder/file" storage/folder cuts the paarameter in half and won't make sense to the shell because user@host:/path/to/directory is one full parameter. You can use parts of it, but you cannot cut it in half or it will be examined as 2 different params.

1
  • Changing quotes within a token (aka word) works fine in any POSIX shell. Example (in bash): foo=bar; echo fine'$foo'more"$foo" -> fine$foomorebar – dave_thompson_085 Apr 20 '18 at 7:35
0

Triple escape works for me:

scp macbook@192.168.0.3:bob\\\'s\\\ file /local/path/

These also work:

scp "macbook@192.168.0.3:bob\'s\ file" /local/path/
scp macbook@192.168.0.3:"bob\'s\ file" /local/path/

These do not:

scp "macbook@192.168.0.3:bob's file" /local/path/
scp macbook@192.168.0.3:bob\'s\ file /local/path/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.