![]() |
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Calling a perl script from a perl script | new2ss | Shell Programming and Scripting | 6 | 05-24-2009 06:03 PM |
| Deciphering the Myths Around Complex Event Processing | iBot | Complex Event Processing RSS News | 0 | 05-21-2008 06:10 PM |
| Help deciphering script | bbbngowc | Shell Programming and Scripting | 3 | 01-16-2008 01:57 PM |
| Modify Perl script to work with txt - Permissions script | joangopan | Shell Programming and Scripting | 1 | 09-13-2007 12:38 AM |
| Perl: Run perl script in the current process | vino | Shell Programming and Scripting | 10 | 12-09-2005 10:45 AM |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
||||
|
Help deciphering FTP get perl script
I found this very useful perl script that will check a remote ftp server, search for files of a specific time and get them. When I run the script it works, but it gave me the following error:
Couldn't get filename_12-13-07.txt Bad file number What in this script would cause this? I know nothing about perl. #!/usr/bin/perl use Net::FTP; $date=shift @ARGV; @months=qw(null Jan Feb Mar Apr My Jun Jul Aug Sep Oct Nov Dec); @hosts=qw(ftp.server.com); @dirs=qw(/); @logins=qw(username); @passwords=qw(password); $x=0; foreach(@months) { $months{$_}=$x++; } # we need this hash later if (not $date) { $now=time(); $now -= (24 * 3600 ); # yesterday ($nowsec,$nowmin,$nowhr,$nowday,$nowmon,$nowyr,$nowdow,$nowdoy,$nowdst)=localtime($now); $nowyr+=1900;$nowmon++; $date=sprintf("%.2d/%.2d/%.4d",$nowmon,$nowday,$nowyr); print "Using $date\n"; } $now=time(); ($nowsec,$nowmin,$nowhr,$nowday,$nowmon,$nowyr,$nowdow,$nowdoy,$nowdst)=localtime($now); $nowyr+=1900; # need $nowyr later ($month,$day,$year)=split /\//,$date; # # broken next century - blame me then # $year+=2000 if $year < 100; $x=0; foreach (@hosts) { $newerr=0; $ftp=Net::FTP->new($_,Timeout=>240) or $newerr=1; push @ERRORS, "Can't ftp to $_: $!\n" if $newerr; next if $newerr; print "Connected $_\n"; $ftp->login($logins[$x],$passwords[$x]) or $newerr=1; push @ERRORS, "Can't login to $_: $!\n" if $newerr; $ftp->quit if $newerr; next if $newerr; print "Logged in $_\n"; $ftp->cwd($dirs[$x]) or $newerr=1; push @ERRORS, "Can't cd $dirs[$x] on $_ $!\n" if $newerr; $ftp->quit if $newerr; next if $newerr; print "Getting file list $_\n"; @files=$ftp->dir or $newerr=1; push @ERRORS, "Can't get file list on $_ $!\n" if $newerr; $ftp->quit if $newerr; next if $newerr; print "Got list $_\n"; print "Looking for $date $time\n"; foreach(@files) { $_=substr($_,41); s/ */ /g; s/^ *//g; chomp; @stuff=split / /; # if it's today, the year slot will have time instead # so make it this year $stuff[2]=$nowyr if /:/; $ftp->quit if ($stuff[2] < $year); next if ($stuff[2] < $year); $ftp->quit if ($months{$stuff[0]} < $month and $stuff[2] == $year); next if ($months{$stuff[0]} < $month and $stuff[2] == $year); $ftp->quit if ($stuff[0] < $day and $stuff[2] == $year and $months{$stuff[0]} == $month); next if ($stuff[1] < $day and $stuff[2] == $year and $months{$stuff[0]} == $month); print "Getting $_\n"; $ftp->get($stuff[3],$stuff[3]) or $newerr=1; push @ERRORS, "Couldn't get $stuff[3] $!\n" if $newerr; } $ftp->quit; } print @ERRORS; exit 0; |
| Bookmarks |
| Tags |
| perl, perl shift, shift, shift perl |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|