Code Comments
Programming Forum and web based access to our favorite programming groups.Wild Pete wrote:
> I have a problem getting an error message using Net::FTP
> when the local file does not exist. $! seems to be empty,
> and $ftp->message() returns a message from a previous
> $ftp->cwd, not from $ftp->put. For example:
>
> $ftp->cwd("$fdir");
> $ftp->put("$file");
> $err=$!;
> $fer=$ftp->message();
> print "put $file failed $err: $fer";
>
> What I get is:
> Cannot open Local file test.txt: No such file or directory
> at test.pl line 36
> put test.txt failed : CDUP command successful.
>
> The "Cannot open" probably went to STDERR, but I can't
> seem to capture that with the above. Is this a bug?
> Suggestions?
Here the corresponding code from Net::FTP:
unless(sysopen($loc, $local, O_RDONLY))
{
carp "Cannot open Local file $local: $!\n";
return undef;
}
}
so the error message goes to STDERR via carp as you suspected. $! is reset
somewhere in between. So you can either test the existence of the local
file yourself before trying to send it (perhaps the best method), or wrap
the $ftp->put in a signal handler like this:
my $errtext;
{
local $SIG{__WARN__} = sub { $errtext = $_[0] };
$ret = $ftp->put($file);
}
print $errtext unless $ret;
Not a bug, but a questionable design perhaps. I would prefer having a
method for the last error. ($ftp->message is only for messages from the
server). IMHO, writing errors to STDERR should be up to the user of the
module. YMMV.
Thomas
--
$/=$,,$_=<DATA>,s,(.*),$1,see;__END__
s,^(.*\043),,mg,@_=map{[split'']}split;{#>J~.>_an~>>e~......>r~
$_=$_[$%][$"];y,<~>^,-++-,?{$/=--$|?'"':#..u.t.^.o.P.r.>ha~.e..
'%',s,(.),\$$/$1=1,,$;=$_}:/\w/?{y,_, ,,#..>s^~ht<._..._..c....
print}:y,.,,||last,,,,,,$_=$;;eval,redo}#.....>.e.r^.>l^..>k^.-
Post Follow-up to this message
Show a Printable Version
Email This Page to Someone!
Receive updates to this thread
Powered by vBulletin
Copyright 2000-2006 Jelsoft Enterprises Limited.