Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: Get the latest file

by biosysadmin (Deacon)
on May 18, 2004 at 15:53 UTC ( [id://354314]=note: print w/replies, xml ) Need Help??


in reply to Get the latest file

As Abigal-II has pointed out, not all FTP servers support transmitting file modification times, and the ones that do may not even transmit them in the same format. I think you have two options:
  • Write a client-side script to parse the output of "ls -l" and grab the latest file
  • Write a server-side script that symlinks the latest file to a known filename, such as "latest"
Here's some example code for the second way of doing things. Some example code is shown below:
#!/usr/bin/perl -w use strict; my $ftp_dir = '/pub/'; my @files = glob("$ftp_dir/*"); my ($latest_file,$modtime) = (0,0); foreach my $file (@files) { my $local_modtime = (stat($file))[9]; if ( $local_modtime > $modtime ) { $latest_file = $file; $modtime = $local_modtime; } } # There's probably a better way to make symlinks `ln -s $ftp_dir/$latest_file $ftp_dir/latest`;
The code is untested, but hopefully it can get the point across.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://354314]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (9)
As of 2024-04-23 14:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found