Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things

Need help on NET:FTP

by bh_perl (Monk)
on Apr 29, 2011 at 06:31 UTC ( #901931=perlquestion: print w/replies, xml ) Need Help??

bh_perl has asked for the wisdom of the Perl Monks concerning the following question:


Below is my script but when i run the script its not collect the input files from remote server. Why ?. Please help me

Run command Line:
./ -i -u baharin -p baharin -r /home/baharin +/data/input -l /home/sysadmin/bh/input -f *.xml

The program code as below:
#!/usr/bin/perl use Net::FTP; use strict; use Getopt::Long; my ($username,$password,$ip,$remotedir,$localdir,$filename,$filemode) += (0,0,0,0,0,0,0); my ($ftp,$success); GetOptions ( "i=s" => \$ip, "u=s" => \$username, "p=s" => \$password, "r=s" => \$remotedir, "l=s" => \$localdir, "f=s" => \$filename, "m=s" => \$filemode ); my $log = "/home/sysadmin/bh/sys.log"; my $err; open (LOGS, ">> $log") or die ("Can't open $log\n"); #$ftp = Net::FTP->new("") or die "Can't connect to 190.2 +54.14.34\n"; $ftp = Net::FTP->new($ip, Timeout=>240) or $err=1; print "LOGIN: $ip\n"; if ($err) { print (LOGS "Can't connect to $ip\n"); $ftp->quit; } $ftp->login("$username","$password") or $err=1; print "LOGIN: $username/$password\n"; if ($err) { print (LOGS "Can't login to $ip with $username, $password\n"); $ftp->quit; } $ftp->binary(); $ftp->cwd("$remotedir") or $err=1; print "LOGIN: $remotedir\n"; if ($err) { print (LOGS "Can't change to directory $remotedir\n"); $ftp->quit; } $ftp->get("$remotedir/$filename") or $err=1; print "LOGIN: DIR\n"; if ($err) { print (LOGS "Can't collect file $filename from dir $remotedir\ +n"); $ftp->quit; } $ftp->quit; close(LOGS);

Replies are listed 'Best First'.
Re: Need help on NET:FTP
by wind (Priest) on Apr 29, 2011 at 07:13 UTC

    What are the results when you run the script? Does it do anything?

    On a side note, you can group your options definition with defaults into one statement

    GetOptions ( "i=s" => \(my $ip = 0), "u=s" => \(my $username = 0), "p=s" => \(my $password = 0), "r=s" => \(my $remotedir = 0), "l=s" => \(my $localdir = 0), "f=s" => \(my $filename = 0), "m=s" => \(my $filemode = 0), );
      may be u r shell expands * in u r input. Give esaped input

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://901931]
Approved by Tanktalus
Front-paged by toolic
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (4)
As of 2023-02-05 20:48 GMT
Find Nodes?
    Voting Booth?
    I prefer not to run the latest version of Perl because:

    Results (32 votes). Check out past polls.