#!/usr/pkg/bin/perl -w # See POD at EOF for full description. use strict; use warnings; use Net::FTP; use Tk; my $host = "192.168.0.1"; my $user = "foo"; my $pw = "bar"; my $server_path = "foo/bar"; my $local_path = "c:/foo/bar"; my $regex = ".*progress|monitor|gui|specimen|station.*txt"; my $sys_local_path; # For dos-ism path. ###################### # Begin GUI stuff ###################### my $label_width = 12; # First declare the main GUI frame and all her daughters. my $mw = MainWindow->new( -title => ' Track Bedplates Via FTP' ); my $frame_1 = $mw->Frame( -relief => 'flat', -borderwidth => 5)->pack( -side => 'top', -expand => 1, -fill => 'x'); $frame_1->Label( -width => $label_width, -text => "Host" )->pack( -side => 'left' ); $frame_1->Entry( -textvariable => \$host, -background => "white", -foreground => 'blue', -relief => 'sunken', -font => 'courier' )->pack( -side => 'left', -expand => 1, -fill => 'x'); my $frame_2 = $mw->Frame( -relief => 'flat', -borderwidth => 5)->pack( -side => 'top', -expand => 1, -fill => 'x'); $frame_2->Label( -width => $label_width, -text => "User" )->pack( -side => 'left' ); $frame_2->Entry( -textvariable => \$user, -background => "white", -foreground => 'blue', -relief => 'sunken', -font => 'courier' )->pack( -side => 'left', -expand => 1, -fill => 'x'); my $frame_3 = $mw->Frame( -relief => 'flat', -borderwidth => 5)->pack( -side => 'top', -expand => 1, -fill => 'x'); $frame_3->Label( -width => $label_width, -text => "Password" )->pack( -side => 'left' ); $frame_3->Entry( -textvariable => \$pw, -show => "*", -background => "white", -foreground => 'blue', -relief => 'sunken', -font => 'courier' )->pack( -side => 'left', -expand => 1, -fill => 'x'); my $frame_4 = $mw->Frame( -relief => 'flat', -borderwidth => 5)->pack( -side => 'top', -expand => 1, -fill => 'x'); $frame_4->Label( -width => $label_width, -text => "Server file path" )->pack( -side => 'left' ); $frame_4->Entry( -textvariable => \$server_path, -background => "white", -foreground => 'blue', -relief => 'sunken', -font => 'courier' )->pack( -side => 'left', -expand => 1, -fill => 'x'); my $frame_5 = $mw->Frame( -relief => 'flat', -borderwidth => 5)->pack( -side => 'top', -expand => 1, -fill => 'x'); $frame_5->Label( -width => $label_width, -text => "RegEx filter" )->pack( -side => 'left' ); $frame_5->Entry( -textvariable => \$regex, -background => "white", -foreground => 'blue', -relief => 'sunken', -font => 'courier' )->pack( -side => 'left', -expand => 1, -fill => 'x'); my $frame_6 = $mw->Frame( -relief => 'flat', -borderwidth => 5)->pack( -side => 'top', -expand => 1, -fill => 'x'); $frame_6->Label( -width => $label_width, -text => "Local file path" )->pack( -side => 'left' ); $frame_6->Entry( -textvariable => \$local_path, -background => "white", -foreground => 'blue', -relief => 'sunken', -font => 'courier' )->pack( -side => 'left', -expand => 1, -fill => 'x'); my $frame_7 = $mw->Frame( -relief => 'flat', -borderwidth => 5)->pack( -side => 'top', -expand => 1, -fill => 'x'); $frame_7->Label( -width => $label_width, -text => "Action" )->pack( -side => 'left' ); $frame_7->Button( -text => ' Download ', -command => \&get_ftp_files, -background => 'gray', -activebackground => 'red', -relief => 'raised', )->pack( -side => 'left', -expand => 1, -fill => 'x' ); $frame_7->Button( -text => ' View ', -command => sub { system('explorer.exe', $sys_local_path ); }, -background => 'gray', -activebackground => 'green', -relief => 'raised', )->pack( -side => 'left', -expand => 1, -fill => 'x' ); MainLoop; ###################### # End GUI stuff ###################### =pod sub show_ftp_files { chdir $local_path; my @downloaded = glob("*.*"); foreach my $file (@downloaded) { system($viewing_program, $file) } } =cut sub get_ftp_files { $sys_local_path = $local_path; $sys_local_path =~ s/\//\\/g; # Insure dos-isms. $local_path =~ s/\\/\//g; # Circumvent dos-isms. $server_path =~ s/\\/\//g; # Circumvent dos-isms. chdir $local_path; if ( my $ftp = Net::FTP->new($host) ) { print "Logging in to '$host' as user '$user'.\n"; $ftp->login($user,$pw) or die "\tOops! Could not login"; $ftp->pasv(); print "Changing directory to '$server_path'\n"; $ftp->cwd($server_path) or die "\tOops! Could not cwd $server_path"; $ftp->binary; # Because Perl is like Unix and will strip CRLF. my @files = $ftp->ls; print "Found these files: \n\t" . join( "\n\t", @files ) . ".\n"; foreach my $file (@files) { if ( $file =~ /.*progress|monitor|gui|station.*txt/ ) { print "Downloading file: $file.\n"; $ftp->get($file) or print "\tOops! Could not get $file\n"; } } $ftp->close(); } else { print "\tOops! Could not connect.\n"; } print "All done.\n"; } __END__ =head1 NAME FTP Download Utility =head1 SYNOPSIS perl B =head1 DESCRIPTION Track the progress of MTS MultiPurpose TestWare tests from outside the testing facility via FTP. =head1 README This script is for downloading by FTP such files as have been uploaded to an ftp server via the companion script B. That other script must run in the the testing facility on the PC controlling the test. This script gets the results from that. This script may be run anywhere. =head1 HOWTO Just run this script from anywhere over the internet. If defaults have been appropriately set, all will occur automatically. =head1 PREREQUISITES Perl script gus_mpt_ftp_put.pl for use in concert. =head1 AUTHOR Gan Uesli Starling > =head1 COPYRIGHT Copyright (c) 2004, Gan Uesli Starling. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =head1 SCRIPT CATEGORIES Misc =cut