On Sunday 17 August 2003 08:51, Cook, Harold D GARRISON wrote: > > I'm having a problem with NET::FTP. Please see code below. My > problem seems to be with the login method call, the error I get is: > Can't call method "login" on an undefined value at putcffile.pl line > 56. > > I know this is not a FW issue because I'm testing by ftp'ing to > myself and I can login in with the credenials I'm using from the cmd > line. OS is W2k. Could problem have something to do with salar > referencing or quoting within NET::FTP? What about using IP # for > host value, is that exceptable? Using debug, socket seems to be > established okay from the call to "Net::FTP->new". Also, is the > method below correct to ensure binary transmisson? > > TIA, > Harold Cook > > #----Begin----
use warnings; > use strict; > use Net::FTP; > use Getopt::Long; > > my $opt_debug = 10; > my $opt_firewall = undef; You are defining lexically scoped variables however Getopt::Long cannot modify their values unless you pass a reference to them to the GetOptions sub. The package variables $opt_debug and $opt_firewall that GetOptions creates are not used by your program > GetOptions(qw(debug firewall=s)); my $opt_debug = 10; my $opt_firewall; GetOptions( 'debug' => \$opt_debug, 'firewall=s' => \$opt_firewall ); Or: our $opt_debug = 10; our $opt_firewall; GetOptions( qw( debug firewall=s ) ); > my @firewall = defined $opt_firewall ? (Firewall => $opt_firewall) : (); Why are you storing a hash in an array? > my $some_dir='c:\\location\\files'; > > my $host='xxx.xx.50.51'; > > my $user='username'; > > my $pass='passwordxx'; > > # Start process to select file > (chdir 'C:/location/files') || die "Can't cd to CacheFlows\BSM directory: $!\n"; ^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^ Which directory are you changing to? > opendir(DIR, $some_dir) || die "can't opendir $some_dir: $!"; > my @files100 = grep { /CF_100_/ && -f "$some_dir/$_" } readdir(DIR); > closedir DIR; > > open(TXT100,">file100.txt") || die "can't open txt"; You should include the file name and the $! variable in the error message. > #print TXT100 "[EMAIL PROTECTED]"; > sort @files100[$#files100]; You are using an array slice to get a single element of the array and then sorting that single element and discarding the result. That is equivalent to: undef = sort $files100[ $#files100 ]; > my $file100 = @files100[$#files100]; You are using an array slice to get the last element of the unsorted array. If you had warnings enabled perl would have warned you about using an array slice when you should have used a scalar. @files100 = sort @files100; my $file100 = $files100[ -1 ]; Or: my $file100 = ( sort @files100 )[ -1 ]; > print TXT100 "$file100\n" ; > close TXT100; > ###call ftp sub here > my $file=$file100; > ftpit($host, $user, $pass, $file); > > > # End select file process > #===== > > > sub ftpit > { > print "$_[0]: $_[1]\n"; > print "$_[2]: $_[3]\n"; > > > my ($host, $user, $pass, $file) = @_; > my $wkdir='/u02/'; > > print 'username= ', $user, ' logging in on host= ', $host, ' > password=xxxxxxxx', "\n"; > print 'sending file: ', $file, "\n"; > > my $ftp = Net::FTP->new($host, @firewall, Debug => $opt_debug ? 1 : 0); ^^^^^^^^^ Net::FTP->new() expects an even numbered list after the first argument which a hash guarentees. Are you sure that there are an even number of elements in @firewall? You should also verify that new was successful. my $ftp = Net::FTP->new( $host, @firewall, Debug => $opt_debug ? 1 : 0 ) or die "Cannot connect to $host: $@"; > my $ftp->login("$user", "$pass") or die "can't login to ftp server", $ftp->message; You don't need to enclose scalar variables in quotes. my $ftp->login( $user, $pass ) or die "Cannot login to $host: ", $ftp->message; > my $ftp->cwd($wkdir); > my $ftp->binary(); > my $ftp->put($file, $file); > my $ftp->quit; > return 1; > } > #----end---- John -- use Perl; program fulfillment -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]