Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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@172.31.72.103:/media/New 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@172.31.72.103:/media/New\ Volume/lj /home/pratheep

but I am still getting the same error.

Can somebody tell me how to correct it?

share|improve this question
add comment

2 Answers

up vote 10 down vote accepted

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@172.31.72.103:"'/media/New Volume/lj'" /home/pratheep
scp -r -P 8484 root@172.31.72.103:'"/media/New Volume/lj"' /home/pratheep

or using the help of tab completion

scp -r -P 8484 root@172.31.72.103:/media/New\\\ Volume/lj /home/pratheep
share|improve this answer
2  
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
add comment

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@172.31.72.103 '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@172.31.72.103:/ mnt
cp -Rp 'mnt/media/New Volume/lj' /home/pratheep
fusermount -u mnt
rmdir mnt
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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