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
  • 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 9 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 9 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 9 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 9 at 13:00
  • What NAS system (or distribution) is this? – Jeff Schaller Jul 9 at 13:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.