As others have remarked, you need to pass the get
commands as input to sftp
. You can do it with a here document. Also, note that sftp
doesn't have a mget
command.
sftp "username@server:$path" <<'EOF'
get ubpbilp* ./
get cust.cmp* ./
get bunc.cmp* ./
EOF
SFTP isn't very convenient to script. If the server allows scp, use it. If you just want to copy some files, it's easier. You can pass patterns on the command line of scp
; make sure to quote them, so that they're expanded on the remote side and not by the local shell. Don't forget the final .
indicating that the destination is the current directory.
scp -p \
"username@server:$path/ubpbilp*" \
"username@server:$path/cust.cmp*" \
"username@server:$path/bunc.cmp*" \
.
If you need to do more than copy files, install SSHFS, if possible. SSHFS provides access to remote files via the normal filesystem mechanism. It uses SFTP under the hood, so if the server allows SFTP, you can use SSHFS, provided that your computer allows client allows FUSE.
mkdir server-dir
trap 'fusermount -u server-dir; rmdir server-dir' 0 HUP INT TERM
sshfs "username@server:$path" server-dir
cp -p server-dir/ubpbilp* cust.cmp* bunc.cmp* .