Using Net::FTP as my network transport component, I have a
situation where I will have a file on my local machine. Call
it 0613x86.exe.
I go to an ftp site and want to figure out if there is a
newer file (perhaps 0615x86.exe). While this sounds easy, I
am having a hell of a time getting the mmdd (Filename)
out of the arrays and files, then doing the comparison as far
as which is the newer file. I have had some help getting
this far and feel close but just need a little extra code.
Thanks very much, I am trying hard to learn Perl on my own,
but I am really struggling with files, arrays, regex, and
how Perl wants those items expressed.
#!/usr/local/bin/perl -w
use Net::FTP;
$host = 'www.ftp.com';
$user = 'anonymous';
$pass = 'updatepuller@ftp.com';
$remote_dir = '/path/to/remote/filesendinginmmddx86.exe';
$oldfilename = `ls current-sig`;
chomp $oldfilename;
$destination_dir= "current-sig";
$ftp = Net::FTP->new($host, Debug => 1);
$ftp->login($user,$pass);
my @listing = $ftp->ls("$remote_dir");
for (@listing) {
if ( /x86\.exe/i ) {
open(FH, ">> myfile.txt") || die "Can't open $file for write: $!";
print FH "$_\n"
}
}
close FH;
#$ftp->get("$remote_dir/$filename","$destination_dir/$filename");
$ftp->pasv();
$ftp->quit;
open( OUT, "> myfile.new") or die "$!";
open( NFH, "myfile.txt") or die( "Cannot open file : $!" ) ;
while (<NFH>) {
#($month,$day) =~ /(\d\d)(\d\d)x86\.exe/
# m/([0-9][0-9][0-9][0-9])/;
print( OUT "$1\n" );
}
#close NFH or die( "Cannot close file: $!" );
#close OUT or die( "Cannot close file: $!" );
#open( NEWTIMES, "<myfile.new") or die "$!";
#while ( <NEWTIMES> ) {
# m/([0-9][0-9])/;
# @month = ("$1\n") ;
# }
#while ( <NEWTIMES> ) {
# s/([0-9][0-9])//;
# @day = ("$1\n") ;
# }
#close NEWTIMES or die( "Cannot close file: $!" );
Edit by dws to clean up title
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.