Hi,
I hope someone can explain if this is the right behaviour. I regularly use scp to copy files between hosts like this:
scp -prv user@remotehost:/path/to/copy .
However, today, I made a mistake and typed this instead:
scp -prv user@remotehost: /path/to/copy .
This started copying user@remotehosts $HOME to . on the local host I was on.
So I have now tried
scp -prv user@remotehost: .
which also copies $HOME to . on the local host. I did not know you could do this. I am under the impression that I must always include a path or at lease /.
What puzzles me further, is how in
scp -prv user@remotehost: /path/to/copy .
it starts writing everything to . instead of /path/to/copy.
Is this the expected behavior? Is it a bug which can be fixed? Could someone please shed some light on this?
I'd consider it a bug, as you've not given any source files -- it should not be finding anything to send. When I try it with my implementation(linux, openssh) I get this error:
scp: .: not a regular file
cp: omitting directory `/path/to/dirname'
If I choose a folder that does not exist on localhost:
scp: .: not a regular file
cp: cannot stat `/path/to/dir2': No such file or directory
Thanks for responding Corona. Can you share what version you run?
My Server runs:
"Linux myhostname 2.6.18-274.el5 #1 SMP Fri Jul 8 17:36:59 EDT 2011 x86_64 x86_64 x86_64 GNU/Linux"
Red Hat Enterprise Linux Server release 5.7 (Tikanga)
openssh-clients-4.3p2-72.el5_6.3
Could anyone confirm this for me?
The kernel and bit width isn't relevant.
My version of openssh is openssh-5.6_p1-r2
It may also have to do with what $HOME ends up being when you scp in there. Might it somehow end up as a file?
No it was actually $HOME of the user. I almost wiped out my data. I did a test afterwards on a test system. It copied all the $HOME data
Well, is the remote system any different from yours? That's just as important. Expansion on the remote side has been sometimes known to occur strangely on proprietary SSH implementations.
The path after : is optional, with the default being the remote user's
home directory. Consider "scp blah.txt user@host:"
For the case of "scp -prv user@remotehost: /path/to/copy .", it's doing
exactly what you tell it: copying user@remotehost's home directory as
well as /path/to/copy to your local home directory.