cancel
Showing results for 
Search instead for 
Did you mean: 

Perl script to FTP

sweetyselvi
Regular Advisor

Perl script to FTP

I need a perl script to ftp the files which is in .txt,.sh and .pl files. once i run this script in unix remote machine it should ftp the files and it should save it in local windows machine. kindly help me..ASAP ,thanks well in advance
9 REPLIES
Steven E. Protter
Exalted Contributor

Re: Perl script to FTP

Shalom,

http://www.dtp-aus.com/cgiscript/allcgi.shtml

That link contains a script you can use as a base to modify for this purpose.

Some assembly required.

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
James R. Ferguson
Acclaimed Contributor

Re: Perl script to FTP

Hi:

And what have you tried to build yourself?

If you look at the CPAN documentation for Net::FTP you will see the essentials. The Net::FTP module is part of the core Perl distrubution since Perl 5.7.

Regards!

...JRF...
sweetyselvi
Regular Advisor

Re: Perl script to FTP

I checked in that link which you have specified , but that all related to CGI perl. i could not able to fine any useful information. Can you able to help in any other way?
James R. Ferguson
Acclaimed Contributor

Re: Perl script to FTP

Hi (again):

Can you able to help in any other way?

Yes, as I said above: If you look at the CPAN documentation for Net::FTP you will see the essentials.

You should easily be able to build what you need.

Regards!

...JRF...
sweetyselvi
Regular Advisor

Re: Perl script to FTP

Hi,

I could not able to find out that document,
is any package required to use this Net::FTP function in perl program.

Because its throughing an error,

"Net::ftp -> pack required"

what can i do now?
James R. Ferguson
Acclaimed Contributor

Re: Perl script to FTP

Hi (again):

The module is 'Net::FTP' and as I said, it is part of any core Perl since 5.7.

http://search.cpan.org/~gbarr/libnet-1.22/Net/FTP.pm

Regards!

...JRF...
sweetyselvi
Regular Advisor

Re: Perl script to FTP

Hi

#!/usr/bin/perl -w
use Net::FTP;
$ftp =Net::FTP->new("IP Address",Debug=> 0) or die "Cannot connect to IP Address:$@";
$ftp->login("ABCD","AAA@123") or die "Cannot login", $ftp->message;
$ftp->cwd("/pub") or die "Cannot change working directory", $ftp->message;
$ftp->get("tool.pl") or die "get failed", $ftp->message;
$ftp->quit;

With the help of perl active state complier i can able to run this script successfully in windows machine, but multiple get(mget) option is not working fine. Its telling

ERROR ->Cannot locat object method "meget" via package "Net::FTP" at xxx.pl

How to include mget function inside this code?

Regards

Selvi

James R. Ferguson
Acclaimed Contributor

Re: Perl script to FTP

Hi (again):

The Perl 'Net::FTP' module does not have a 'mget' function (as the error you received tells you, too).

To implement a multiple get or put you need to build your own list/array of filenames and perform 'get' or 'put' operations as you iterate over each element.

Regards!

...JRF...
Paul Mata
Occasional Visitor

Re: Perl script to FTP

This is the script I use to upload files to my server. Simply edit the file to include your host, username, and password and invoke it at the command line with the file names that you want to upload as the arguments. (i.e. - "perl perlftp.pl file1.txt file2.sh file3..." Hope this helps.

#!/usr/bin/perl
#perlftp.pl


use Net::FTP;
@files = @ARGV;

$remotehost = "some.server.com";
$remotedir = "/remoter/dir";
$user = "username";
$pass = "password";

print "Connecting...\n";

$ftp = Net::FTP->new("$remotehost", Debug => 0) or
die "cannot connect:";

print "Logging in...\n";
$ftp->login("$user","$pass")
or die "cannot login: ",$ftp->message;

print "Changing to $remotedir...\n";
$ftp->cwd($remotedir)
or die "cannot cwd to $remotedir: ",$ftp->message ;

print "Beginning Transfer...\n";

foreach $file (@files)
{
print "xfering $file..\n";
$ftp->put($file);
$ftp->message;

}

print "Done.\n";