Search code examples
bashftpmget

Supplying dynamic pattern (YYYYMMDD) as ftp mget pattern


I am writing a script that supposed fetch today's files (about a dozen) from an FTP site using mget like so

ftp -n XX.XX.XX.XX <<END_SCRIPT
mget *20190703*
quit
END_SCRIPT

Ideally I'd do something like mget 'date +%Y%m%d' (apostrophe used in lieu of a literal backtick) but that's not possible. I'd appreciate any pointers


Solution

  • Below code segment should work: Kindly check.

    event_date=`date +%Y%m%d`
    ftp -n -i XX.XX.XX.XX <<END_SCRIPT
    mget *${event_date}*
    quit
    END_SCRIPT
    

    or you may look in below script: we use this script in production

    event_date=`date +%Y%m%d`
    lftp -p [port number] -u user_name,'password' sftp://ip <<HERE_DOC
    cd file_directory
    mget *${event_date}*
    bye
    HERE_DOC