I want to download only specific files from a server which could have other files too. So I am using the below mget commands. But if PO*.txt don't exist, it exits and doesn't continue to get INV*.txt. Do I have to connect twice to the sftp server and download them individually?

mget PO*.txt
mget INV*.txt

I am calling from a korn shell script. I am using the below command:

sftp -oBatchMode=no -b - -oIdentityFile=~/.ssh/id_rsa $p_sftp << EOF > $p_tmpfile cd /outgoing
mget PO*.asc
mget INV*.asc

1 Answer 1


The sftp aborts on error, if you have specified -b switch on its command-line only. So remove it, if you do not want to abort (note that the - is an argument to the -b, so you need to remove whole -b -).

Though in this case, you might want to ignore only errors in the first [m]get command only.

For that, prefix the command with a dash (-).

-get PO*.txt
get INV*.txt

(Note that sftp does not really have mget command. It has get, with mget get being its undocumented alias.)

  • 1
    Perfect - removing -b - solved my issue. Thanks again for your help & guidance.
    – maskeerr
    Mar 11, 2021 at 21:36

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .