Perl scirpt for automatic file transfer

Hi ,
can any one help me with a perl script for automating file transfer ?
At each step i need to check for the success or failure .
I am trying to connect to the target system for a specified number of times.if it doesnt connect even after 3 retries then the script should exit.
and i have to take the list of files on the source directory and should FTP each one to the target directory.
And i have to record the number of files that could be sent successfully and the number of failures and also save the names of the files for reporting.
Please help.
Thanks in advance

You need to use the Net::FTP module to perform the actual FTP'ing. Reading the source directory on disk can be with primitive functions such as opendir() and readdir(). Or there are modules on CPAN that will do this with a more OO syntax such as DirHandle or IO::Dir.

The other requirements are trivial, as Net::FTP functions give return values that allow you to check whether each operation is successful. Maybe you can try with these lines of thought first.

Thank you.
but i already wrote the basic code for file transfer using perl.
all i want is a more detailed one with the conditions that i mentioned.
regards
srini

Hi friends, i have written a basic script for automating ftp of files from source directory to a destination directory on a different host. But how can i get the list of files in the source directory so that i can keep track of the files which went successfully and unsuccessful files ? thanks in advance srini

The primitive way (without considering recursive dir listing) is very easy and can be along the lines of

$MY_DIR="/my/dir";
opendir(DIR, $MY_DIR);
my @files = readdir(DIR);
my @plain_files = sort map {
    (-f "$MY_DIR/$_")?($_):()
} @files;
foreach (@plain_files) {
    # FTP of $_ here (e.g. /my/dir/myfile)
}

Hi cbkihong,
Thank you so much for the code.
it works well.
actually i had some other problem which is solved with your code.
excellant job cbkihong.
bye
srini

Hi cbkihong,
I am doing an iteration on each file in the local directory and then if the ftp fails then i am doing a retry for a fixed number of times.
if ftp fails the first time then i am saying continue to the next trial
or else to break.
for this i wrote the code as

for($try=1;$try<=$retry_file_ftp;$try++)
{
print "filename is ::$i\n";
$ftp->put("$local_directory/$i") or $newerr=1;

if \($newerr ==1\)
  continue;
 else
   break;

}
}

but its giving some syntax error at continue.
i am not able to figure it out .
can u please help ?
thanks in advance
bye
srini

hi all,
i checked the perl man page and could correct my mistake
thanks
bye
srini

I'm new and have searched but can not find what I am looking for.

I need to use sftp in a perl script but we can not load the NET::SFTP module at this time.

Many examples of using NET::SFTP but no examples of doing a system call to use sftp.

Any suggestions are appreciated and much thanks!