FTP from one directory to another using perl

Hi All
I am stuck with a problem and i want your help,

I have two directories dir1 and dir2
The files present in dir1 is a1,a2 a3 a4

What i want to is to FTP the files present in the dir1 to dir2 (with .txt extension at the end.) with the help of the Perl.

The output expected is
The files should come in dir2 as a1.txt, a2.txt, a3.txt, a4.txt

what you tried so far ?

did you use any ftp module ?

The code which i have tried so far is

use strict;
use Net::FTP;
use Date::Manip;

while (my $file = readdir(DIR)) 
 {
         # Use a regular expression to ignore files beginning with a period
         next if ($file =~ m/^\./);
         #FTP 
         ftpfile($file);
          if($ftp_status==0) 
         {
             print "FTP not successful.\n";
         }
         else 
         {
            print  "FTP successful.\n";
         }

    
}
sub ftpfile {
$file = @_;
    my $ftp = Net::FTP->new($config->getconf('FtpHost')) or die "Can't connect to FTP host: $@\n";
    $ftp->login($config->getconf('FtpUser'), $config->getconf('FtpPassword')) or die "Can't login to FTP Server\n";
    $ftp->cwd($config->getconf('PutDir')) or die "Can't change directory\n";
    $ftp->put($file) or die "Can't put $_ \n"; 
    $ftp_status=1;
    }

what error you are getting ?

It doesn't give the error but the file is not transferred.
Any new idea

why you are assigning $ftp_status=1; ?

Just for conformation that ftp for that document has been done sucessfully

can you replace your method with below and check whether it prints the correct file name and is there any error message..

 
sub ftpfile {
$file = @_;
print "File Name : $file \n";
    my $ftp = Net::FTP->new($config->getconf('FtpHost')) or die "Can't connect to FTP host: $@\n" , $ftp->message;
    $ftp->login($config->getconf('FtpUser'), $config->getconf('FtpPassword')) or die "Can't login to FTP Server\n" , $ftp->message;
    $ftp->cwd($config->getconf('PutDir')) or die "Can't change directory\n" , $ftp->message;
    $ftp->put($file) or die "Can't put $_ \n", $ftp->message; 
    $ftp->quit;
}

The following error it gave
Cannot open Local file 1: No such file or directory
at /home/ssss/testshch/test.pl line 54
Use of uninitialized value in concatenation (.) or string at /home/sgupta1/testshch/test.pl line 54.
Can't put
CWD command successful.

---------- Post updated at 06:07 AM ---------- Previous update was at 06:06 AM ----------

I think it is treating the file a1 as 1
a2 as2
a3 as3 like that

is the below statement executed ?

print "File Name : $file \n";

File Name : 1
Cannot open Local file 1: No such file or directory
at /home/ssss/testshch/test.pl line 54
Use of uninitialized value in concatenation (.) or string at /home/sgupta1/testshch/test.pl line 54.
Can't put
CWD command successful.

---------- Post updated at 06:58 AM ---------- Previous update was at 06:58 AM ----------

The file name is a1 but it is taking as 1, i don't know why??

I have two directories dir1 and dir2
The files present in dir1 is a1,a2 a3 a4

What i want to is to FTP the files present in the dir1 to dir2 with the help of the Perl.

The output expected is
The files should come in dir2 as a1,a2,a3,a4
Any idea till not solved

Hi,
i have decloped the code, but the following error is coming.

#!/etc/bin/perl -w
use Net::FTP;
use strict;
my $ddir='/home/sssss/test/';
my $dfile='abc.txt';
open(fhe , ">$ddir$dfile") || die "unable to create report file $ddir$dfile  $!";
print fhe  "Report\n";
print fhe "testting\n";
print fhe "testing Report\n";
close fhe;
ftpReport();
sub ftpReport {
   my $host = 'pppppp';
   my $user = 'ssssss';
   my $pass = 'qqqqqq';
   my $output_dir = '/home/sssss/infolder';
         my $ftp = Net::FTP->new($host) || die "Unable to establish ftp connection to $host";
        $ftp->login($user, $pass) || die "Unable to log into $host as $user/$pass";
        $ftp->cwd($output_dir) || die "unable to change directory to $output_dir\n";
       $ftp->put("$ddir$dfile") || die "Unable to ftp $dfile to $host.\n";
        $ftp->quit();

The error is

Unquoted string "fhe" may clash with future reserved word at ./tttt.pl line 7.
Unquoted string "fhe" may clash with future reserved word at ./tttt.pl line 8.
Unquoted string "fhe" may clash with future reserved word at ./tttt.pl line 9

---------- Post updated at 06:29 AM ---------- Previous update was at 06:28 AM ----------

What is the possible way to remove the warning