0

Following a previous answer I'm trying to list the files on an FTP server that match a pattern, as shown below

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

Unfortunately this does not work. Is there a way to list these files, apart from listing all files and grep'ing on the client side i.e.

event_date=`date +%Y%m%d`
ftp -n XX.XX.XX.XX <<END_SCRIPT
ls * all_files.dat
quit
END_SCRIPT
grep $event_date all_files.log > todays_files.dat
Jeff Schaller
  • 66,199
  • 35
  • 114
  • 250
Olumide
  • 167
  • 8
  • Does not work in what way? The `ls` in FTP will expand globs. What do you get vs what do you expect? It seems like you're expecting your `ls` command in the here-document to redirect to some output file (todays_files.dat or all_files.dat) but as-written you're asking ftp's `ls` to list that file on the remote side. Intended? – Jeff Schaller Jul 09 '19 at 12:38
  • @JeffSchaller In the original snippet `todays_files.dat` is empty i.e. no files are listed. If however I write `ls *20190709* today_files.dat` , `todays_files.dat` contains files on the FTP server whose names contain the substring "20190709". – Olumide Jul 09 '19 at 12:45
  • Ahh; I get a prompt to output the results (`output to local-file`); your FTP client must automatically assume that action. Do you have a peculiar FTP client? – Jeff Schaller Jul 09 '19 at 12:53
  • @JeffSchaller All of the above commands are executed in a bash script. The client ftp is the standard client that shipped with the distro (a NAS box). The server is running proftp. – Olumide Jul 09 '19 at 13:00
  • What NAS system (or distribution) is this? – Jeff Schaller Jul 09 '19 at 13:01
  • It's a QNAP box. I don't know what distro it runs. – Olumide Jul 09 '19 at 13:18
  • This seems (to me) like important information, to help answerers understand what software we're dealing with. Could you please edit that information into the question? Thank you! – Jeff Schaller Jul 09 '19 at 13:19
  • Let us [continue this discussion in chat](https://chat.stackexchange.com/rooms/95912/discussion-between-olumide-and-jeff-schaller). – Olumide Jul 09 '19 at 13:21
  • I get the same behavior on a Centos 7 machine, so its unlikely to be caused by the distro of the NAS device. – Olumide Jul 09 '19 at 14:13
  • My ftp client says `ls` is used to list a directory given by name, not a file. You could try `mls` to list a file glob pattern such as you have. – meuh Jul 09 '19 at 18:02
  • @meuh `mls *${event_date}*` does not work. I've gone with listing all files and filtering out the those that match the date YYYYMMDD. – Olumide Jul 10 '19 at 10:29

0 Answers0