Hi Guys,
I am new to perl scripting. I'm trying to get files from some servers. The names of the servers are stored in a file.
Now if I use this code, it doesn't work:
open(INFO, "$txtfile"); # Open the file
while (<INFO>) {
($var1, $var2) = split(/ /,$_,2);
$line = ftpvar("$var1", "$var2");
print("$line\n");
}
close(INFO);
sub ftpvar{
$myvar1 = $_[0];
$myvar2 = $_[1];
print("$myvar1\n");
print("$myvar2\n");
my $ftp = Net::FTP->new("$myvar2", Debug=>1, Timeout => 120);
return (error=>'Could not login to FTP server') unless $ftp;
$ftp->login("user",'password');
$ftp->cwd("$source_dir");
@dirList = $ftp->ls("*$myvar1*");
$ftp->binary();
foreach $file (@dirList) {
$ftp->get("$file", "$copy_dir/$file");
}
$ftp->quit();
}
But if do it like this, it works:
$var1 = "value1";
$var2 = "value2";
$line = ftpvar("$var1", "$var2");
sub ftpvar{
$myvar1 = $_[0];
$myvar2 = $_[1];
print("$myvar1\n");
print("$myvar2\n");
my $ftp = Net::FTP->new("$myvar2", Debug=>1, Timeout => 120);
return (error=>'Could not login to FTP server') unless $ftp;
$ftp->login("user",'password');
$ftp->cwd("$source_dir");
@dirList = $ftp->ls("*$myvar1*");
$ftp->binary();
foreach $file (@dirList) {
$ftp->get("$file", "$copy_dir/$file");
}
$ftp->quit();
}
I have verified that the values I pass in ftpvar is correct. I really am lost now what is wrong with the code. Thanks for the help!
I am new to perl scripting. I'm trying to get files from some servers. The names of the servers are stored in a file.
Now if I use this code, it doesn't work:
open(INFO, "$txtfile"); # Open the file
while (<INFO>) {
($var1, $var2) = split(/ /,$_,2);
$line = ftpvar("$var1", "$var2");
print("$line\n");
}
close(INFO);
sub ftpvar{
$myvar1 = $_[0];
$myvar2 = $_[1];
print("$myvar1\n");
print("$myvar2\n");
my $ftp = Net::FTP->new("$myvar2", Debug=>1, Timeout => 120);
return (error=>'Could not login to FTP server') unless $ftp;
$ftp->login("user",'password');
$ftp->cwd("$source_dir");
@dirList = $ftp->ls("*$myvar1*");
$ftp->binary();
foreach $file (@dirList) {
$ftp->get("$file", "$copy_dir/$file");
}
$ftp->quit();
}
But if do it like this, it works:
$var1 = "value1";
$var2 = "value2";
$line = ftpvar("$var1", "$var2");
sub ftpvar{
$myvar1 = $_[0];
$myvar2 = $_[1];
print("$myvar1\n");
print("$myvar2\n");
my $ftp = Net::FTP->new("$myvar2", Debug=>1, Timeout => 120);
return (error=>'Could not login to FTP server') unless $ftp;
$ftp->login("user",'password');
$ftp->cwd("$source_dir");
@dirList = $ftp->ls("*$myvar1*");
$ftp->binary();
foreach $file (@dirList) {
$ftp->get("$file", "$copy_dir/$file");
}
$ftp->quit();
}
I have verified that the values I pass in ftpvar is correct. I really am lost now what is wrong with the code. Thanks for the help!