tags:

views:

74

answers:

2

I am trying to automate the download of a file using wget and calling the php script from cron, the filename always consists of filename and date, however the date changes depending on when the file is uploaded. The trouble is there is no certainty of when the file is updated, and hence the final name can never really be known until the directory is checked.

An example filename is file20100818.tbz

I tried using wildcards within wget but they have failed, both using * and %

Thanks in advance,

Greg

+2  A: 

Assuming the file type is constant then from the wget man page:

You want to download all the GIFs from a directory on an HTTP server. You tried wget http://www.server.com/dir/*.gif, but that didn't work because HTTP retrieval does not support globbing. In that case, use:

wget -r -l1 --no-parent -A.gif http://www.server.com/dir/

So, you want to use the -A flag, something like:

wget -r -l1 --no-parent -A.tbz http://www.mysite.com/path/to/files/
Stephen
of course this will only work if the server answers with a file listing of the requested directory, if it doesn't, you can only guess the filename as shown by shamittomar.
Sven Koschnicke
A: 

You can for loop each date like this:

<?php
for($i=0;$i<30;$i++)
{
     $filename = "file".date("Ymd", time() + 86400 * $i).".tbz";
     //try file download, if successful, break out of loop.
?>

You can increase number of tries in for loop.

shamittomar