I'm using the scp commands to pull some files from the remote server and one variation of the command is not working.
I have 2 files names one.xml and two.xml in a remote server and I'm pulling these two files into the current dir using the following command:
scp [email protected]:/student/class/Intermediate/one.xml .
scp [email protected]:/student/class/Intermediate/two.xml .
The above command works fine but if I use wildcards to pull all the xml files in a single shot as shown below it returns scp: No match.
scp [email protected]:/student/class/Intermediate/*.xml .
Why is it working if I pull the files individually and not working if I try to pull using wildcards.
2 Answers
Yeah this is for SuperUser. The answer is because the asterisk does a wildcard expansion FIRST before the command even runs. It is expanded by your SHELL. echo *.xml will really run echo file1.xml file2.xml and that is what echo sees, while bash sees the *.xml.
Since you are passing multiple files and paths to SCP, it gets confused as the first argument (or 2nd) is not a host:/path.
Put 'echo' in front of your command to see what is really being executed. You can't use wildcards on a remote host (unless you escape them first).
You can clarify from these results
You can simplify this process a lot by tunneling ssh connections over other ssh connections (see this previous answer). The way I'd do it is to create an .ssh/config file on the LOCAL system with the following entries:
Host SYSTEM3
ProxyCommand ssh -e none SYSTEM2 exec /usr/bin/nc %h %p 2>/dev/null
HostName SYSTEM3.full.domain
User system3user
Host SYSTEM2
ProxyCommand ssh -e none SYSTEM1 exec /usr/bin/nc %h %p 2>/dev/null
HostName SYSTEM2.full.domain
User system2user
Host SYSTEM1
HostName SYSTEM1.full.domain
User system1user
(That's assuming both intermediate hosts have netcat installed as /usr/bin/nc -- if not, you may have to find/install some equivalent way of gatewaying stdin&stdout into a TCP session.)
With this set up, you can use scp SYSTEM3:/data /data on LOCAL, and it'll automatically tunnel through SYSTEM1 and SYSTEM2 (and ask for the passwords for the three SYSTEMn's in order -- this can be a little confusing, especially if you mistype one).