thanks John...my problem is solved....am trying to add more functionalities to the script. Will seek help again if faced with any issue..
On Tue, May 26, 2009 at 11:31 AM, John W. Krahn <jwkr...@shaw.ca> wrote: > Mihir Kamdar wrote: > >> Hi, >> >> I want to write a perl script which will get files from multiple >> directories >> in remote location using FTP. Following is the script that I tried:- >> >> #!/usr/bin/perl >> use Net::FTP; >> use strict; >> for (my $count=0; $count < 2; $count++) >> { >> print "Please enter the directory name to ftp files: \n" ; >> my $dir=<>; >> chomp $dir ; >> my $ftp = Net::FTP->new("10.48.2.68",Debug => 0) or die "not connected:"; >> $ftp->login("report",'report') or die "Cant login", $ftp->message; >> $ftp->cwd("$dir") or die "Cant change working directory", $ftp->message ; >> $ftp->get($_) for grep /\*KO_SPLT\*/, $ftp->ls or die "get failed >> ",$ftp->message ; >> > > Your problems are because of this line above which could also be written > as: > > foreach ( grep /\*KO_SPLT\*/, $ftp->ls or die "get failed ", $ftp->message > ) { > > $ftp->get($_) > } > > Your regular expression pattern matches exactly the string '*KO_SPLT*' but > there are no '*' characters in the string '07_KOL_KO_SPLT_20090402.txt.gz' > so grep returns an empty list which is false and the program dies with your > error message. > > What you probably want is something more like: > > $ftp->binary; > $ftp->get( $_ ) or die "get failed ", $ftp->message for grep /KO_SPLT/, > $ftp->ls; > > > $ftp->quit ; >> } >> >> But the get fails. Following message comes:- >> >> rangerfm:/home/ranger/subex_working_area/TEST :>perl ftp1.pl >> Please enter the directory name to ftp files: >> /backup2/dailyreportbackup/20090402 >> get failed Opening ASCII mode data connection for file list. >> Transfer complete. >> >> There is a file in the above mentioned directory which is >> "07_KOL_KO_SPLT_20090402.txt.gz". >> I want to ftp this file. >> >> Can you please help on why "get" is failing in this case. Since mget >> doesnt >> work with Net::FTP, I found an alternative way on net which I tried using. >> > > > John > -- > Those people who think they know everything are a great > annoyance to those of us who do. -- Isaac Asimov > > -- > To unsubscribe, e-mail: beginners-unsubscr...@perl.org > For additional commands, e-mail: beginners-h...@perl.org > http://learn.perl.org/ > > >