I am trying to copy files using secure copy(scp). I am trying to execute the following command but I get error due to the space in the absolute path of the location of the directory.

scp -r -P 8484 root@ Volume/lj /home/pratheep

I am getting the following error:

scp: /media/New: No such file or directory  
scp: Volume/lj: No such file or directory

I tried using the same command putting extra back slash like

scp -r -P 8484 root@\ Volume/lj /home/pratheep

but I am still getting the same error.

Can somebody tell me how to correct it?


You should quote your file name two times, one for the local shell and one for the remote one. In the simplest case you can do one of the following

scp -r -P 8484 root@"'/media/New Volume/lj'" /home/pratheep
scp -r -P 8484 root@'"/media/New Volume/lj"' /home/pratheep

or using the help of tab completion

scp -r -P 8484 root@\\\ Volume/lj /home/pratheep
  • 3
    It is helpful to note that scp uses ssh as its transport which explains why there are two passes of shell interpretation happening. – msw Feb 6 '12 at 14:47

scp and rsync pass remote file names to the remote shell. This allows you to pass patterns, as in

scp remotehost:'*.txt' .

but it has the nasty consequence that you need extra quoting when supplying a remote file name.

You can pass the -s option to rsync to make it protect the file names from expansion by the remote shell. But that turns on rsync's built-in wildcard expansion, so you still need to quote \[?*.

A workaround is to transfer an archive:

ssh -P 8484 root@ 'cd "/media/New Volume" && tar cf - lj' |
tar xf - -C /home/pratheep

Another method is to mount the remote filesystem, and then use ordinary tools to perform the copy.

mkdir mnt
sshfs -p 8484 root@ mnt
cp -Rp 'mnt/media/New Volume/lj' /home/pratheep
fusermount -u mnt
rmdir mnt

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.