1

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

Olumide
  • 5,397
  • 10
  • 55
  • 104

1 Answers1

2

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
Olumide
  • 5,397
  • 10
  • 55
  • 104
Milon Sarker
  • 478
  • 8
  • 25
  • I'm getting `mget file1_20190701.ext? mget file2_20190701.ext? mget file1_20190701.ext? ...` . As I see `mget` is waiting for prompts. – Olumide Jul 04 '19 at 10:35
  • you will get all files with \*20190701\*pattern ... use second code segment ... it wont ask for password ... using in hundreds script .... btw if port is default ... then no need to give that data. – Milon Sarker Jul 04 '19 at 10:38
  • Unfortunately the backup device I am copying to only supports FTP (_boo_). I think its because mget has sync features tho. – Olumide Jul 04 '19 at 10:40
  • Update adding the flag `-i` seems to do the trick i.e. `ftp -n -i XX.XX.XX.XX` – Olumide Jul 04 '19 at 10:42
  • @Olumide its really odd. However, still this can be handled I guess. Try to write a loop. – Milon Sarker Jul 09 '19 at 13:08