How to scp multiple files from remote to local in a folder other than ~/?

I'm trying to make a bash expect script that takes in input like user, host, password, and file names and then copies the files from remote to local. From what I've read so far, scp'ing multiple files from remote to local works just fine when you're assuming the files are coming from ~/, i.e:

scp -r user@host:"file1 file2 file3" .

would copy file1, file2, and file3 from ~/ into the current working directory. But I need to be able to pass in another directory as an argument, so my bash script looks like this (but doesn't work, I'll explain how):

eval spawn scp -oStrictHostKeyChecking=no -oCheckHostIP=no -r $user@$host:$dir/"$file1 $file2 $file3" ~/Downloads

This doesn't work after the first file; the shell raises a "No such file or directory" error after the first file, which I would assume means that the script only works on $dir for the first file, then kicks back into ~/ and of course can't find the files there. I've looked everywhere for an answer on this but can't find it, and it would be super tedious to do this one file at a time.


Assuming your remote login shell understands Brace Expansion, this should work

scp $user@$host:$dir/"{$file1,$file2,$file3}" ~/Downloads

If you want to download multiple files with an specific pattern, you can do the following for example if you want all zip files:

scp -r user@host:/path/to/files/"*.zip" /your/local/path