Home > Archive > PERL Miscellaneous > December 2004 > write error message to a log file while processing the ftp command
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
write error message to a log file while processing the ftp command
|
|
|
| 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
| |
| Joe Smith 2004-12-07, 4:11 am |
| Jing wrote:
> 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
| |
| Charles DeRykus 2004-12-07, 4:11 am |
| In article <815c0a36.0412031711.7a5578a7@posting.google.com>,
Jing <jingchai@gmail.com> wrote:
>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;" }
--
Charles DeRykus
|
|
|
|
|