Hello lftp users,

I'm using lftp for a project at the EBU (http://www.ebu.ch/, 
http://www.eurovision.net/, http://tech.ebu.ch/) and I need to get and parse 
the status line (e.g. "`/data1/2011/ER11041216.rm' at 1349536 (2%) 215.2K/s 
eta:4m [Sending data]") when lftp runs detached (i.e. without a terminal tty, 
isatty() == 0).

Currently I managed to do this by creating the following perl wrapper to lftp:

#!/usr/bin/perl -w

use strict;
use Expect;

$SIG{INT}       = \&sig_handler;
$SIG{QUIT}      = \&sig_handler;
$SIG{TERM}      = \&sig_handler;
$SIG{KILL}      = \&sig_handler;

$| = 1;

my $args = join(' ', @ARGV);

my $exp = new Expect;
$exp->raw_pty(1);
$exp->slave->clone_winsize_from(\*STDIN);
$exp->log_stdout(0);
$exp->log_file(\&logger);
$exp->spawn("lftp $args") or die "Cannot spawn lftp $args: $!\n";
$exp->expect(undef);
$exp->soft_close();
exit(0);

sub logger {
        my $status = shift;

        $status =~ s/\x1B\x5B\x30\x30\x6D//g;
        $status =~ tr/\x00-\x1F//d;
        $status =~ s/^\s+//;
        if ($status) {
                print "$status\n"
        };
}

sub sig_handler {
        my $sig = shift;

        $exp->hard_close();
        exit(1);
}

My question is: would it be possible to add a switch to always have the status 
line being displayed (as text, withous special terminal characters) or to 
create an additional xml-like output that could be parsed by some other 
controlling programs?

Anticipating thanks and best regards,
Nicolas Mizel




_______________________________________________
lftp mailing list
lftp@uniyar.ac.ru
http://univ.uniyar.ac.ru/mailman/listinfo/lftp

Reply via email to