Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

Re: Net::FTP error when local file does not exist
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^.-

Report this thread to moderator Post Follow-up to this message
Old Post
Thomas Kratz
09-28-04 09:00 PM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

PERL Modules archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 05:34 PM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.