Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Posting to nntp newsgroup with Perl (Net::NNTP)

Reply
Thread Tools

Posting to nntp newsgroup with Perl (Net::NNTP)

 
 
sadie-no-reply
Guest
Posts: n/a
 
      03-04-2007
I am trying to post a message to a newsgroup using Net::NNTP, but I keep
getting an error message. Help!
I can read from the newsgroup without problems and $nntp->postok() gives OK.
I suspect there's something wrong with way I've constructed my message
array.
Here's the code.

use Net::NNTP;

$server="news.yourserver.com"; #replace this with your nntp server name

#connect to the nntp server (this works fine)
$nntp = Net::NNTP->new($server);

#open a newsgroup (this works fine)
$nntp->group("nl.test") or die "cannot open nl.test";

#download and print the last message (this works fine)
$articleId = $nntp->last();
@tekst = $nntp->article($articleId);
for ($i=1; $t=$tekst[0][$i]; $i++)
{print $t."<BR>\n";}

#check if I'm alowed to post (returns: ok)
if ($nntp->postok())
{print "Posting would be ok\n";}else
{print "Posting not ok\n";}

#construct a message - I'm not sure about this.
#For example, should there be \r\n at the end of each line??
@message=(
"Subject: this is test 1\r\n",
"From: cllq\@noreply.nil\r\n",
"Newsgroups: nl.test\r\n",
"Date: Sat, 3 Mar 2007 20:14:13 +0100\r\n",
"\r\n",
"This is my message\r\n",
"Yours sincerely\r\n",
"Bla\r\n");

#now post the message
$nntp->post(@message) or die "post failed"; #this one fails, but why?
$nntp->quit();

#alternative code that also fails:
$nntp->post() or die "post failed"; #this one ok
$nntp->datasend(@message) or die "datasend nok"; #this one ok
$nntp->dataend() or die "dataend nok"; #this one fails but why?
$nntp->quit();


 
Reply With Quote
 
 
 
 
Peter J. Holzer
Guest
Posts: n/a
 
      03-04-2007
On 2007-03-04 12:05, sadie-no-reply <(E-Mail Removed)> wrote:
> I am trying to post a message to a newsgroup using Net::NNTP, but I keep
> getting an error message. Help!

[...]
> #now post the message
> $nntp->post(@message) or die "post failed"; #this one fails, but why?


Why ask us? Ask perl:

$nntp->post(@message) or die "post failed: " . $nntp->message();

hp


--
_ | Peter J. Holzer | Es ist ganz einfach ihn zu verstehen, wenn
|_|_) | Sysadmin WSR | man nur alle wichtigen Worte im Satz durch
| | | http://www.velocityreviews.com/forums/(E-Mail Removed) | andere ersetzt.
__/ | http://www.hjp.at/ | -- Nils Ketelsen in danr
 
Reply With Quote
 
 
 
 
sadie-no-reply
Guest
Posts: n/a
 
      03-04-2007
Thanks for the tip. It returns:
340 <45eb1d1b$0$3748$(E-Mail Removed)> (desired) Article has no
body -- just headers

After checking RFC977&850, I changed @message into:

@message=(
"Subject: dit is test 2
From: cllq\@noreply.nil
Newsgroups: nl.test
Date: Sat, 4 Mar 2007 20:45:13 +0100

Hier staat de eerste regel
Hier de tweede
..");

And it seems to work. At least returns ok status. Haven't seen the result
back, though...

"Peter J. Holzer" <(E-Mail Removed)> schreef in bericht
news:(E-Mail Removed)...
> On 2007-03-04 12:05, sadie-no-reply <(E-Mail Removed)> wrote:
>> I am trying to post a message to a newsgroup using Net::NNTP, but I keep
>> getting an error message. Help!

> [...]
>> #now post the message
>> $nntp->post(@message) or die "post failed"; #this one fails, but why?

>
> Why ask us? Ask perl:
>
> $nntp->post(@message) or die "post failed: " . $nntp->message();
>
> hp
>
>
> --
> _ | Peter J. Holzer | Es ist ganz einfach ihn zu verstehen, wenn
> |_|_) | Sysadmin WSR | man nur alle wichtigen Worte im Satz durch
> | | | (E-Mail Removed) | andere ersetzt.
> __/ | http://www.hjp.at/ | -- Nils Ketelsen in danr



 
Reply With Quote
 
Jamie
Guest
Posts: n/a
 
      03-05-2007
In <45eb3cf1$0$13606$(E-Mail Removed)>,
"sadie-no-reply" <(E-Mail Removed)> mentions:
>Thanks for the tip. It returns:
>340 <45eb1d1b$0$3748$(E-Mail Removed)> (desired) Article has no
>body -- just headers
>
>After checking RFC977&850, I changed @message into:
>
>@message=(
>"Subject: dit is test 2
>From: cllq\@noreply.nil
>Newsgroups: nl.test
>Date: Sat, 4 Mar 2007 20:45:13 +0100
>
>Hier staat de eerste regel
>Hier de tweede
>.");
>
>And it seems to work. At least returns ok status. Haven't seen the result
>back, though...


You might look into the datasend(), dataend() methods of Net::Cmd (these
are inherited by Net::NNTP, so you can use them withing a $nntp object
as well)

Not saying it's proper, but I generally just use telnet combined with
Net::Cmd and Net::NNTP. (actually, you could easily just use Net::Cmd if
you wanted) telnet for debugging and getting a feel for what the perl
modules are doing.


# The critical bits from one of my "inews" clone scripts:
#
# I left out the connect and alarm wrappers.
#
$nntp->post();
while(my $line = <>){
$nntp->datasend($line);
}
$nntp->dataend();
unless($nntp->ok()){
die sprintf("NNTP[%03d] %s\n",$nntp->code(),$nntp->message());
}

Try posting a small article (to a test group) with telnet to get a feel
for how NNTP works. It'll make using the perl modules easier.

Jamie
--
http://www.geniegate.com Custom web programming
Perl * Java * UNIX User Management Solutions
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[ANN] NNTP client Library ruby-net-nntp 1.0.0 released Anton Bangratz Ruby 0 06-04-2008 03:12 PM
Cannot authenticate to NNTP server with Net::NNTP authinfo() usenet@DavidFilmer.com Perl Misc 7 08-09-2006 06:36 PM
nntp.perl.org posting problem Mark Day Perl Misc 2 11-04-2004 01:57 AM
bottom posting nntp ??? posting for email T.N.O. NZ Computing 21 09-15-2003 08:21 AM
Re: NNTP Posting Host Davin Mickelson MCSE 0 07-18-2003 06:16 PM



Advertisments