1753448 Members
5137 Online
108794 Solutions
New Discussion юеВ

Re: PERL script

 
Praveen Ravi
Occasional Contributor

PERL script

How to transfer a directory in FTP using PERL script?
i have tried transfering single files using the put command. But i m not able to use the mput command in PERL script
4 REPLIES 4
Pete Hakesley
Advisor

Re: PERL script

Hi,

There are two ways I would attack this problem.
1. Use the perl module Net::FTP which has lots of functions built about ftp'ing multiple files and indeed all te ftp functions possible as if on the command line.

2. I have in the past used "expect" scripts to automate actions that require user input such as ftp, scp etc.

Expect is simple to use and understand.
see http:://expect.nist.gov/

You can exven cheat a little and use autoexpect to macro record your actions on the command line and use as the basis of your script.

Regards,
Pete
Alexander Chuzhoy
Honored Contributor

Re: PERL script

I'm not sure about Net::FTP, but you can transfer directories with Net::FTP::Recursive module.
Here's a working example, that will download all the contents (including subdirectories) of the /pub directory.
#!/usr/bin/perl
use Net::FTP::Recursive;
$ftp = Net::FTP::Recursive->new("", Debug => 0);
$ftp->login("username",'password');
#$ftp->cwd('/pub');
$ftp->rget( ParseSub => \&yoursub );
$ftp->quit;

sub yoursub {
$ftp->rget;
}


You will need to install this module on your machine (download it from:
http://search.cpan.org/~jdlee/Net-FTP-Recursive-2.00/), as it's not there by default.
Praveen Ravi
Occasional Contributor

Re: PERL script

what wil be the change in case of put.
actually i dont want to get directories.
i want to put some directories with files inside.

i also didnt understand the line where u called the subroutine.
Alexander Chuzhoy
Honored Contributor

Re: PERL script

Change directory to a directory that holds directories with files.From that directory

run the following script and it will update those directories to the FTP.

#!/usr/bin/perl
use Net::FTP::Recursive;
$ftp = Net::FTP::Recursive->new("", Debug => 0);
$ftp->login("username",'password');
$ftp->rput( ParseSub => \&yoursub );
$ftp->quit;

sub yoursub {
$ftp->rput;
}

For more information read here:
http://search.cpan.org/~jdlee/Net-FTP-Recursive-2.00/Recursive.pm