ftp in perl

Hi,

I have three files in this /home/mani/ location. I would like to ftp to another server.

could you please give perl for that requirement.

Thanks,
Mani

The Net::FTP module documentation has a lot of examples. Why don't you take a look first and try it out

I tried, but i got error messaage. like Can't locate object method "mput" via package "Net::FTP" at ./get_local_mq_info.pl line 40, <CMD> line 3.

Please help

What exactly did you try?

while(<CMD>) {
system("runmqsc $qm <$cmdfile >$uat_log/$qm.data"); -- three files are stored this location
$ftp = Net::FTP->new("Hostname",Debug => 0)
or die "Cannot connect to gcssu1: $@";
$ftp->login("mani",'mani123')
or die "Cannot login ", $ftp->message;
$ftp->cwd("/tmp2/prodlog/uat_logs")
or die "Cannot change working directory ", $ftp->message;
$ftp->put("$uat_log/$qm.data")
or die "get failed ", $ftp->message;
$ftp->quit;
}

That can't be all of your code, since CMD isn't opened anywhere, and it's nowhere near 40 lines long. Pretty sure you didn't post whatever line the error happened at.

I have tried like this also :

#!/usr/bin/perl

#use Net::FTP;

$uat_log='uat_log';

chdir("$uat_log");
@dir = <*>;
foreach $file (@dir) {
print $file . "\n";
use Net::FTP;
$ftp = Net::FTP->new("gcssu1",Debug => 0)
or die "Cannot connect to gcssu1: $@";
$ftp->login("AVC5DH",'GCSS321')
or die "Cannot login ", $ftp->message;
$ftp->cwd("/tmp2/prodlog/uat_logs")
or die "Cannot change working directory ", $ftp->message;
$ftp->put("$file")
or die "get failed ", $ftp->message;
$ftp->quit;
}

Error : get failed GCSXDUA01.data: Permission denied.

Please advice

check whether you already having a file called "GCSXDUA01.data" in /tmp2/prodlog/uat_logs

The error means what it says, I'm pretty sure. You don't have permission to put files in that directory. This isn't controlled by your perl code, but by file and directory permissions on your FTP server. Or perhaps you don't have permissions to access the file locally?

Other than that it seems to work -- it connects to FTP.

One hint, you don't have to connect to FTP 20 times to transfer 20 files. You can connect once and reuse the connection over and over.

Exactly Corona688 . There is no permission on that /tmp2/prodlog/uat_logs location.. When its good pretty good. Finally one . If it transfer the same once again it mean it will be replace the old one ?

Thanks,
Mani

I think so. why not try it?