Search code examples
bashscp

Bash scp failure?


For example I'm trying to do a simple scp:

scp tzj21@example.co.uk:/home/tzj21/scratch/McAdam/chains/z0.5/temp_cc1/* .

It fails when there are obviously files in the folder and simply returns scp: No match.? I'm fairly sure this used to work before. When I try:

scp tzj21@example.co.uk:/home/tzj21/scratch/McAdam/chains/z0.5/temp_cc1/1.txt .

it works just fine. Is this to do with the server I'm trying to scp to preventing me from transferring all files?

Edit: Solved. Main problem was me being inside tcsh rather than bash.


Solution

  • You need to expand * (to all files) on the remote shell, not on the local shell.

    Any regular escaping method to prevent pre-expansion of * on the local shell would do:

    scp tzj21@example.co.uk:/home/tzj21/scratch/McAdam/chains/z0.5/temp_cc1/'*' .
    scp tzj21@example.co.uk:/home/tzj21/scratch/McAdam/chains/z0.5/temp_cc1/"*" .
    scp tzj21@example.co.uk:/home/tzj21/scratch/McAdam/chains/z0.5/temp_cc1/\* .
    

    Or you can quote the whole filename string as well:

    scp tzj21@example.co.uk:'/home/tzj21/scratch/McAdam/chains/z0.5/temp_cc1/*' .
    scp tzj21@example.co.uk:"/home/tzj21/scratch/McAdam/chains/z0.5/temp_cc1/*" .