bschultz Posted February 22, 2015 Share Posted February 22, 2015 I work at a radio station. Each week, we have to download (using SCP or wget) a bunch of mp3's to air during the weekend. The problem I'm having is that the remote directory that these files are located in changes the name from one week to another. For instance, this week one directory is named 'Live In Concert ROCK (Sunday) 02.22.15 version3'. Next week, it might be 'Live In Concert ROCK (Sunday) 02.29.15 version2' What I need is a matching pattern of 'Live in Concert' and the 'date'...and there will be other stuff in between those two patterns. To complicate this...it's on a remote machine. What are my options? Thanks. Quote Link to comment Share on other sites More sharing options...
tryingtolearn Posted February 23, 2015 Share Posted February 23, 2015 What are my options? options for what? Quote Link to comment Share on other sites More sharing options...
syed Posted February 23, 2015 Share Posted February 23, 2015 What software does the remote machine have installed? web server? if so , are the mp3 in a web directory? Quote Link to comment Share on other sites More sharing options...
Psycho Posted February 23, 2015 Share Posted February 23, 2015 What are you trying to accomplish by creating a pattern? Are you trying to dynamically determine which folder to download files from? If so, you can (pretty sure) download the folder list and compare the names to do that. I've not used FTP functions in PHP enough to know. But, in determining the pattern, I assume you want to look for a specific data based on the current day's date. It appears you want to always use a Sunday date. So, how do want to choose "which" Sunday to use? I assume if it is Monday to Saturday, you want to use the next Sunday. But, what if you run the code on a Sunday? Should it use the current date or the next week's Sunday? Quote Link to comment Share on other sites More sharing options...
QuickOldCar Posted February 24, 2015 Share Posted February 24, 2015 If you have permission the other server add a script to find the latest folder by date. If not ask them to do it. something like this <?php function latestDirectory($path = NULL) { if ($path == NULL) { $path = "/"; } $list = array(); $path = rtrim($path, "/"); if (substr($path, 0, 1) != "/") { $path = "/" . $path; } if ($path == "/") { $path = $_SERVER['DOCUMENT_ROOT']; } else { $path = $_SERVER['DOCUMENT_ROOT'] . $path; } $working_dir = getcwd(); chdir($path); $ret_val = false; if ($p = opendir($path)) { while (false !== ($file = readdir($p))) { if ($file{0} != '.' && is_dir($file)) { $timestamp = filemtime($path . '/' . $file); $pretty_date = date("m/d/Y h:i:s A", $timestamp); $list[] = array( "directory" => $path . '/' . $file, "date" => $pretty_date, "timestamp" => $timestamp ); } } rsort($list); } chdir($working_dir); //return list array; return $list; } $list_array = latestDirectory(); //use directory names,document root included in function if (!empty($list_array)) { //last directory created echo $list_array['0']['directory']; //list of directories echo "<pre>"; print_r($list_array); echo "<pre>"; } ?> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.