Search code examples
linuxbashshelllftp

Shell - LFTP - multiple extensions


I have been trying to find a way to use mget with only certain file extensions.

I have used following command (which works just fine if I leave *.csv)

lftp -e "set xfer:clobber true;mget $SOURCE_DIR*.{csv,txt,xls,xlsx,zip,rar};exit" -u $SOURCE_USERNAME,$SOURCE_PASSWORD $SOURCE_SERVER || exit 0

But no luck, I get message dir/*.{csv,txt,xls,xlsx,zip,rar} no files found

Tried to add parenthesis

lftp -e "set xfer:clobber true;mget $SOURCE_DIR(*.{csv,txt,xls,xlsx,zip,rar});exit" -u $SOURCE_USERNAME,$SOURCE_PASSWORD $SOURCE_SERVER || exit 0

Also no luck

$SOURCE_DIR already has a slash / at the end

I tried to test lftp locally but I have problem with opening ports on my Vagrant box, hence the question


Solution

  • I managed to connect to one FTP without the need to forward ports.

    Turns out (I know it seems obvious) you have to specify full path with the wildcard for each extension

    mget $SOURCE_DIR*.csv $SOURCE_DIR*.txt

    separated by space

    Also if one (or more) extensions are not found the message "*.txt no files found" will land in standard error, which led me to not be able to proceed with the full script