write error message to a log file while processing the ftp command

J

Jing

The system admin. has a problem to configure the Makefile.pl for
Net::FTP module. my program need to ftp a local files to a remote
server. Since i can't use Net::FTP, i try to use ftp command instead.
I got trouble to write error message to a log file while processing
the ftp command. Here is my code for ftp files.
#!/opt/perl/bin/perl -w

use File::Copy;
$remotehost1 ="a";
$remotepath ="/b";
$remoteuser ="c";
$remotepass ="d";
$fileftp = "test.txt";
$dirfrom="/e";
$cmd="ftp -n";

my $ftp_commands =
" open $remotehost1
user $remoteuser $remotepass
lcd $dirfrom
cd $remotepath
asc
put $fileftp
bye
";
open (CMD, "|$cmd");
print CMD $ftp_commands;
close (CMD);
print "Ftp commands : $ftp_commands";
print "File $fileftp has been transferred \n";
$finish = 'temp';
copy ("$fileftp","./$finish/$fileftp");
thanks
 
B

Brian McCauley

Jing said:
The system admin. has a problem to configure the Makefile.pl for
Net::FTP module. my program need to ftp a local files to a remote
server. Since i can't use Net::FTP, i try to use ftp command instead.
I got trouble to write error message to a log file while processing
the ftp command.

I'm not sure what you are asking but I suspect it may be FAQ: "How can I
open a pipe both to and from a command?".

Personally I think that FAQ answer is incomplete.

It should say first "You may be able to avoid the problem by rediecting
one to/from a temparary file" (for details see my post about this last
week).
 
J

Joe Smith

Jing said:
I got trouble to write error message to a log file
while processing the ftp command.

So, you want to send commands to ftp's STDIN and be able to
capture the error messages it sends to STDERR, right?
Use the IPC::Open3 module for that.
-Joe
 
C

Charles DeRykus

The system admin. has a problem to configure the Makefile.pl for
Net::FTP module. my program need to ftp a local files to a remote
server. Since i can't use Net::FTP, i try to use ftp command instead.
I got trouble to write error message to a log file while processing
the ftp command. Here is my code for ftp files.
#!/opt/perl/bin/perl -w

use File::Copy;
$remotehost1 ="a";
$remotepath ="/b";
$remoteuser ="c";
$remotepass ="d";
$fileftp = "test.txt";
$dirfrom="/e";
$cmd="ftp -n";

my $ftp_commands =
" open $remotehost1
user $remoteuser $remotepass
lcd $dirfrom
cd $remotepath
asc
put $fileftp
bye
";
open (CMD, "|$cmd");
print CMD $ftp_commands;
close (CMD);
print "Ftp commands : $ftp_commands";
print "File $fileftp has been transferred \n";
$finish = 'temp';
copy ("$fileftp","./$finish/$fileftp");

Just launching a backticked command instead of IPC::Open3
may be simpler and just as good in some (not all) cases.
(perldoc -q capture for details).

my $ftp_output = qx/ $ftp_commands 2>&1 / ;
if ($?) { $sig= $? & 127; $err= $?>>8; die "ftp: err=$err sig=$sig\n;" }
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,236
Members
46,822
Latest member
israfaceZa

Latest Threads

Top