CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
d/l help pt 2

 



alexz
stranger

Jul 24, 2001, 12:04 PM

Post #1 of 4 (1565 views)
d/l help pt 2 Can't Post

if i have a file already on my computer and i want to write a prog in perl that will check an ftp to see if there is an updated version of the file, and then d/l it if it is updated, what is the code? i already know the code (thanks to the post below) for downloading files off of an ftp, but i am unsure on how to check to see if the file is an updated version. thank you for any help!

-alex



mhx
Enthusiast / Moderator

Jul 24, 2001, 12:22 PM

Post #2 of 4 (1562 views)
Re: d/l help pt 2 [In reply to] Can't Post

The Net::FTP module also offers a method called mdtm that returns the modification time of a remote file. You can use Perl's stat function to determine the modification time of the local file (see perldoc -f stat for details). Comparing the results of both calls, you can easily determine if the server file is newer than the local file.
Hope this helps.

-- Marcus


Code
s$$ab21b8d15c3d97bd6317286d$;$"=547269736;split'i',join$,,map{chr(($*+= 
($">>=1)&1?-hex:hex)+0140)}/./g;$"=chr$";s;.;\u$&;for@_[0,2];print"@_,"



mhx
Enthusiast / Moderator

Jul 24, 2001, 12:33 PM

Post #3 of 4 (1562 views)
Re: d/l help pt 2 [In reply to] Can't Post

And since you asked for some code, this should give you an idea:

Code
#!/bin/perl -w 
use strict;
use Net::FTP;

my $file = "CTAN.sites";
my $ftp = Net::FTP->new('ftp.dante.de');

$ftp->login('anonymous', 'me@here.de');
$ftp->cwd('/pub/tex');

if( -e $file and $ftp->mdtm($file) <= (stat $file)[9] ) {
print "File is up-to-date\n";
}
else {
print "Need update, downloading...\n";
$ftp->get($file);
}

$ftp->quit;

Hope this helps.

-- Marcus


Code
s$$ab21b8d15c3d97bd6317286d$;$"=547269736;split'i',join$,,map{chr(($*+= 
($">>=1)&1?-hex:hex)+0140)}/./g;$"=chr$";s;.;\u$&;for@_[0,2];print"@_,"



alexz
stranger

Jul 24, 2001, 1:09 PM

Post #4 of 4 (1561 views)
Re: d/l help pt 2 [In reply to] Can't Post

thanks a lot, you're a lifesaver. i really appreciate the help.


 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives