Gossamer Forum
Home : General : Perl Programming :

capturing FTP responses

Quote Reply
capturing FTP responses
I'm using Tk and Net::FTP to build a gui FTP client. I can see the responses on the command line while the program is running. How do I capture them to a text widget instead of the command line?

Philip
------------------
Limecat is not pleased.
Quote Reply
Re: [fuzzy logic] capturing FTP responses In reply to
I use Net::FTP on my LSQL installation script (I set it up as a web-based domain, so I can upload copies of LSQL to customers sites.), as I really don't enjoy uploading 6-7mb files on dial-up. I've never managed to actually 'capture' error messages... but only the commands run. For example;

print $ftp->site('CHMOD 0666 install.dat');

if you work out how to do this, please let me know.. as I would be very interested:)

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] capturing FTP responses In reply to
Hm... just found this on Google, seems to work:

Code:
my $log = $window->Text()->pack;

tie(*STDERR, 'Tk::Text', $log);

$SIG{'__WARN__'} = sub { print STDERR @_ };

I'll have to see if I can cut out all the junk first and have just the responses. Looks like it should be posible since a copy of STDERR seems to be stored in @_;

Philip
------------------
Limecat is not pleased.
Quote Reply
Re: [fuzzy logic] capturing FTP responses In reply to
Getting closer....

Apparently you can't directly manipulate STDERR before it gets printed (makes since now that I think about it). What I've come up with is a subroutine that grabs the current Text data and empties the Text box. I then split it up and parse out the Net::FTP junk that gets prepended to everything, discarding blank lines and Perl warnings that also make their way into the Text widget. I can then insert only what I want back. This gets run after every command. Unfortunately however, sometimes there's a noticable delay between when the raw data gets printed and when it gets parsed and re-printed.

Code:
sub fix_log {
$log->update;
my @log = split /\n/, $log->get("1.0", "end");
$log->delete("1.0", "end");
foreach my $line (@log) {
if ($line !~ /^Net\:\:FTP/ && $line !~ /^\s*$/) {
$log->insert("end", "$line\n")
}
elsif ($line =~ /(>>>|<<<)\s+(.+)$/) {
$log->insert("end", "$2\n");
}
else {
next
}
}
}

Philip
------------------
Limecat is not pleased.