Remote names passed to
scp are actually interpreted as a whitespace-separated list of patterns on the remote side. This is often an annoyance when you try to copy a file whose name contains spaces, but here it's useful:
scp -p 'user@machine:/path/a*' . would copy all files whose name begins with
Your command will work if you quote the pattern so that it's interpreted remotely rather than locally, provided you pass another hurdle. The pattern
!(a*) is not a basic shell pattern, it's a ksh extension (that bash and zsh also support if you set the appropriate option). So this will only work if your remote shell is ksh, not if it's some other shell and you
exec ksh from
.profile or something similar.
The easy way, unless you're in some kind of restricted or antique environment, is to forget about
scp. You'd like remote files to work just like local files, so make them local files: mount the remote directory with sshfs. This requires FUSE on the local machine and an SFTP server (i.e. an
sftp-server executable that
sshd launches) on the remote machine.
sshfs user@machine:/ ~/net/machine
cp -p ~/net/machine/path/!(a*) .