Thread View: news.software.nntp
10 messages
10 total messages
Started by syoder
Mon, 20 Aug 2001 22:44
posting news to NNTP server from Windows
Author: syoder
Date: Mon, 20 Aug 2001 22:44
Date: Mon, 20 Aug 2001 22:44
10 lines
1024 bytes
1024 bytes
Is there a simple way to post to a NNTP server from a MS-DOS command shell (Windows 98/NT/2000) or batch file. How do I post a 'Hello World' message? Thanks, Stuart Yoder
Re: posting news to NNTP server from Windows
Author: Curt Welch
Date: Mon, 20 Aug 2001 23:43
Date: Mon, 20 Aug 2001 23:43
30 lines
1802 bytes
1802 bytes
syoder@parthus.com (syoder) wrote: > Is there a simple way to post to a NNTP server from a > MS-DOS command shell (Windows 98/NT/2000) or batch > file. > > How do I post a 'Hello World' message? Not that I know of. You can do by hand with the telnet command. Something like: telnet news.yourserver.com 119 authinfo user xxx authinfo pass yyy post Subject: Hello World Newsgroups: alt.test From: syoder@parthus.com (syoder) I did it! . If you can figure out how to do that from a batch file you will have it made. -- Curt Welch http://CurtWelch.Com/ curt@kcwc.com Webmaster for http://NewsReader.Com/
Re: posting news to NNTP server from Windows
Author: Thomas A. Horsley
Date: Tue, 21 Aug 2001 12:03
Date: Tue, 21 Aug 2001 12:03
9 lines
1593 bytes
1593 bytes
> Is there a simple way to post to a NNTP server from a > MS-DOS command shell (Windows 98/NT/2000) or batch > file. If you want to install perl and the libnet module for it, there is a Net::NNTP module that can be used to do the mechanics of reading or posting news to an NNTP server. See www.perl.com for pointers to perl (you can probably get precompiled windows binaries at activestate.com).
Re: posting news to NNTP server from Windows
Author: syoder
Date: Tue, 21 Aug 2001 13:46
Date: Tue, 21 Aug 2001 13:46
40 lines
1982 bytes
1982 bytes
Apart from the default shell commands available in Windows, does anyone know of an existing WIN32 program that could do this. Something like: win32nntp_poster -S mysever.com -s 'my subject' mymessage.txt Are there APIs in Windows (Visual C++) that I could use to write a simple program? Thanks, Stuart curt@kcwc.com (Curt Welch) wrote in message news:<20010820194326.182$Dw@newsreader.com>... > syoder@parthus.com (syoder) wrote: > > Is there a simple way to post to a NNTP server from a > > MS-DOS command shell (Windows 98/NT/2000) or batch > > file. > > > > How do I post a 'Hello World' message? > > Not that I know of. You can do by hand with the telnet command. > > Something like: > > telnet news.yourserver.com 119 > > authinfo user xxx > authinfo pass yyy > post > Subject: Hello World > Newsgroups: alt.test > From: syoder@parthus.com (syoder) > > I did it! > . > > If you can figure out how to do that from a batch file you will have > it made.
Re: posting news to NNTP server from Windows
Author: Bert Hyman
Date: Tue, 21 Aug 2001 13:53
Date: Tue, 21 Aug 2001 13:53
19 lines
1612 bytes
1612 bytes
syoder@parthus.com (syoder) wrote in news:ad07e1ae.0108210546.69429233@posting.google.com: > ... > Are there APIs in Windows (Visual C++) that I could use to > write a simple program? > Sure; use CAsyncSocket. Establish a session with the server on port 119 and have a little conversation with it. You'll have to know a little bit of the NNTP protocol in order to generate the message correctly and to understand the server's responses, but for this simple function there's not a lot to do. -- Bert Hyman | St. Paul, MN | bert@visi.com
Re: posting news to NNTP server from Windows
Author: remove 'nospam' to reply
Date: Tue, 21 Aug 2001 17:16
Date: Tue, 21 Aug 2001 17:16
407 lines
9603 bytes
9603 bytes
syoder wrote:
> Is there a simple way to post to a NNTP server from a
> MS-DOS command shell (Windows 98/NT/2000) or batch
> file.
>
> How do I post a 'Hello World' message?
>
> Thanks,
>
> Stuart Yoder
Here is some c code which does it for you.
/*
*/
#ifndef POST_UNIX
#ifndef POST_NT
#error One of (POST_UNIX, POST_NT) must be defined
#endif
#endif
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
#include <string.h>
#include <ctype.h>
/* various flavors of Unix */
#ifdef POST_UNIX
/* (g)cc -DPOST_UNIX post.c -o post (-lsocket -lm -lnsl) */
#include <unistd.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/time.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netdb.h>
/* perror to be called after failed socket calls */
#define perror_sock perror
/* how to close a socket */
#define close_sock close
#endif
/* Windows NT, /subsystem:console. The executable is supposed to work
under NT and Windows 95, but not under Win32s. */
#ifdef POST_NT
/* important note: when compiling on NT, say something like
cl /DPOST_NT /Ogaityb1 /G5Fs /ML post.c wsock32.lib */
#include <winsock.h>
#include <time.h>
/* regular perror doesn't work with WinSock under NT */
#define perror_sock(s) fprintf(stderr,"%s : WinSock error
%d\n",s,WSAGetLastError())
/* regular close doesn't work with WinSock under NT */
#define close_sock closesocket
/* NT doesn't understand unix-style sleep in seconds */
#define sleep(n) Sleep(n*1000)
#endif
#ifndef FD_ZERO
/* macros for select() not defined on VAX or HPUX
However they are defined to be something completely different
under NT WinSock, so we must use macros */
#define fd_set int
#define FD_ZERO(p) {*(p)=0;}
#define FD_SET(s,p) {*(p)|=(1<<(s));}
#define FD_ISSET(s,p) ((*(p)&(1<<(s)))!=0)
#endif
#define ASCII_CR 13
#define ASCII_LF 10
/* seconds */
#define TIMEOUT 12000
#define BUFFERSIZE 4096
char buffer[BUFFERSIZE];
int cfd; /* socket handle */
int parse_state; /* for parsing server responses */
int nretry; /* number of retries in various places */
int nbytes;
short int port=119;
int post_recv_resp(char);
int post_test_sock(int);
int main(int argc,char**argv)
{
unsigned long host_ip;
struct hostent *host_struct;
struct in_addr *host_node;
struct sockaddr_in serverUaddr;
#ifdef POST_NT
WSADATA wsaData; /* needed for WSAStartup */
#endif
if (argc!=2 && argc!=4)
{
fprintf(stderr,"Usage: post nntp-server [user [pass]] <article-file\n\
Usenet article with headers is read from standard input.\n");
return(1);
}
#ifdef SIGPIPE
signal(SIGPIPE,SIG_IGN); /* ignore broken pipes if this platform knows
them */
#endif
#ifdef POST_NT
if (WSAStartup(MAKEWORD(1,1),&wsaData))
{
perror_sock("WSAStartup()");
fprintf(stderr,"couldn't start up WinSock\n");
return(0);
}
fprintf(stderr,"Found WinSock: %s\n",wsaData.szDescription);
#endif
/* translate the hostname (argv[1]) into an ip address. If it starts
with a digit,
try to interpret it as a A.B.C.D address */
if (!isdigit(*argv[1])||(0xFFFFFFFF==(host_ip=inet_addr(argv[1]))))
{
fprintf(stderr,"Resolving host name to IP with DNS\n");
if (NULL==(host_struct=gethostbyname(argv[1])))
{
perror("gethostbyname");
fprintf(stderr,"DNS can't resolve host name %s to IP\n",argv[1]);
return(1);
}
host_node=(struct in_addr*)host_struct->h_addr;
fprintf(stderr,"Trying to connect to NNTP server at %s, ^C to
stop\n",inet_ntoa(*host_node));
host_ip=host_node->s_addr;
}
/* fill in the address to connect to */
memset(&serverUaddr,0,sizeof(serverUaddr));
serverUaddr.sin_family=PF_INET;
serverUaddr.sin_addr.s_addr=/*htonl*/(host_ip); /* already in net order
*/
serverUaddr.sin_port=htons(port);
/* try to create a socket */
if ((cfd=socket(AF_INET,SOCK_STREAM,0))<0)
{
perror_sock("socket()");
return(1);
}
conn1:
if (0>=connect(cfd,(struct sockaddr*)&serverUaddr,sizeof(serverUaddr)))
goto conn2;
if (nretry>10000)
{
fprintf(stderr,"give up trying to connect to %s port %hd\n",
argv[1],port);
close_sock(cfd);
return(1);
}
perror_sock("connect()");
nretry++;
sleep(1);
goto conn1;
conn2:
if (!post_recv_resp('2'))
{
fprintf(stderr,"NNTP problem after connecting to %s port %hd\n",
argv[1],port);
close_sock(cfd);
return(1);
}
if (argc==4) /* user and password */
{
sprintf(buffer,"authinfo user %s\r\n",argv[2]);
nbytes=strlen(buffer);
/* send the user name to the server */
if (nbytes!=send(cfd,buffer,nbytes,0))
{
perror_sock("send authinfo user()");
return(1);
}
if (!post_recv_resp('3'))
{
fprintf(stderr,"NNTP problem while trying to send authinfo user\n");
return(1);
}
sprintf(buffer,"authinfo pass %s\r\n",argv[3]);
nbytes=strlen(buffer);
/* send the password to the server */
if (nbytes!=send(cfd,buffer,nbytes,0))
{
perror_sock("send authinfo pass()");
return(1);
}
if (!post_recv_resp('2'))
{
fprintf(stderr,"NNTP problem while trying to send authinfo pass\n");
return(1);
}
} /* end user and password */
/* send the post command to the server */
if (6!=send(cfd,"POST\r\n",6,0))
{
perror_sock("POST send()");
return(1);
}
if (!post_recv_resp('3'))
{
fprintf(stderr,"NNTP problem while trying to post\n");
return(1);
}
fprintf(stderr,"Sending the article from stdin\n");
while(NULL!=fgets(buffer,sizeof(buffer),stdin))
{
nbytes=strlen(buffer);
if (nbytes && buffer[nbytes-1]=='\n') /* trailing lf from fgets */
nbytes--;
while (nbytes && buffer[nbytes-1]==' ') /* trailing spaces */
nbytes--;
if (nbytes==1 && buffer[0]=='.')
{
/* single dot to dot-space */
nbytes++;
buffer[1]=' ';
}
buffer[nbytes]='\r';
nbytes++;
buffer[nbytes]='\n';
nbytes++;
buffer[nbytes]=0;
if (nbytes!=send(cfd,buffer,nbytes,0))
{
perror_sock("send stdin line()");
return(1);
}
}
fprintf(stderr,"Waiting for the OK\n");
if (3!=send(cfd,".\r\n",3,0))
{
perror_sock("POST send()");
return(1);
}
if (!post_recv_resp('2'))
{
fprintf(stderr,"NNTP problem while trying to post\n");
return(1);
}
fprintf(stderr,"Success!\n");
return(0);
}
int post_recv_resp(char c)
{
int i;
parse_state=0;
nretry=0;
recv_resp:
if (!post_test_sock(cfd)) /* nothing to read */
{
if (nretry>TIMEOUT)
{
fprintf(stderr,"timeout waiting to recv response\n");
return(0);
}
fprintf(stderr,".");
nretry++;
sleep(1);
goto recv_resp;
}
nbytes=recv(cfd,buffer,sizeof(buffer),0);
if (nbytes<0) /* an error shouldn't happen here */
{
perror_sock("response recv()");
return(0);
}
/* #ifdef DEBUG */
fwrite(buffer,1,nbytes,stderr); /* for debugging only!! */
/* #endif */
/* now see if what we received makes sense */
for (i=0; i<nbytes; i++)
{
switch(parse_state)
{
case 0:
if (buffer[i]==c)
parse_state=1;
else
goto recv_bad_resp;
break;
case 1:
if (buffer[i]==ASCII_CR)
parse_state=2;
break;
case 2:
if (buffer[i]==ASCII_LF)
parse_state=3;
else
goto recv_bad_resp;
break;
case 3: /* more data after final \n */
goto recv_bad_resp;
}
}
if (parse_state!=3)
goto recv_resp;
/* normal competion */
return(1);
recv_bad_resp:
fprintf(stderr,"Unexpected response (expected %cxx message) ",c);
if (i)
{
fprintf(stderr,"after \"");
fwrite(buffer,1,i,stderr);
fprintf(stderr,"\" ");
}
if (i<nbytes)
{
fprintf(stderr,"before \"");
fwrite(buffer+i,1,nbytes-i,stderr);
fprintf(stderr,"\"");
}
fprintf(stderr,"\n");
return(0);
}
/* use select to see if there's data here.
There don't seem to be any unixes left which understand poll and not
select.*/
int post_test_sock(int sock)
{
fd_set setm;
static struct timeval zerotime={0,0};
FD_ZERO(&setm);
FD_SET(sock,&setm);
if (select(sock+1,&setm,NULL,NULL,&zerotime)<0)
{
perror_sock("select()");
}
if (FD_ISSET(sock,&setm))
return(1);
else
return(0);
}
Usage:
post Usenet-server <file
or
post Usenet-server user pass <file
The text file should already contain
All the Usenet headers that you want included, in any random order:
Required
Newsgroups:
Subject:
From:
Date: (e.g. Sat, 1 Apr 94 14:15:16 GMT)
Recommended
Path:
Message-id:
Organization:
Optional
Approved:
Keywords:
Supersedes: (another article's message-id)
Distribution:
Followup-To:
Expires: (same format as Date:)
X-Newsreader:
X-Pedophile:
X-Face:
etc.
Followed by a single blank line, followed by the body of your article.
Re: posting news to NNTP server from Windows
Author: fnews
Date: Tue, 21 Aug 2001 17:23
Date: Tue, 21 Aug 2001 17:23
28 lines
1633 bytes
1633 bytes
remove 'nospam' to reply <nospam@nospam.nospam> wrote in news:3B829754.3E62CA6B@nospam.nospam: > > > syoder wrote: > >> Is there a simple way to post to a NNTP server from a >> MS-DOS command shell (Windows 98/NT/2000) or batch file. >> >> How do I post a 'Hello World' message? >> >> Thanks, >> >> Stuart Yoder > > Here is some c code which does it for you. Sure, but if it takes input from stdin, telnet news.server 119 will do the same, with a few commands : authinfo user user authinfo pass pass mode reader group group_to_post post <message>, end with a dot on the line.
Re: posting news to NNTP server from Windows
Author: Curt Welch
Date: Tue, 21 Aug 2001 17:36
Date: Tue, 21 Aug 2001 17:36
22 lines
1893 bytes
1893 bytes
remove 'nospam' to reply <nospam@nospam.nospam> wrote: > All the Usenet headers that you want included, in any random order: > > Required > > Newsgroups: > Subject: > From: > Date: (e.g. Sat, 1 Apr 94 14:15:16 GMT) Date is a required header but it's not required in the article you send to the server. The server will add it for you. It's best if you leave it off and just let the server add it because it's more likely that the sever will get it right. If your timezone isn't set correctly on your PC (far too many aren't set correctly) then the Date will be wrong and that can cause the article to be dropped in transit. -- Curt Welch http://CurtWelch.Com/ curt@kcwc.com Webmaster for http://NewsReader.Com/
Re: posting news to NNTP server from Windows
Author: syoder
Date: Tue, 21 Aug 2001 21:31
Date: Tue, 21 Aug 2001 21:31
5 lines
1071 bytes
1071 bytes
Thanks for all the responses-- I think I have enough info to get this working. Stuart
Re: posting news to NNTP server from Windows
Author: Frank Slootweg
Date: Wed, 22 Aug 2001 09:45
Date: Wed, 22 Aug 2001 09:45
18 lines
1457 bytes
1457 bytes
A little (too?) late response, but ... I have not tried it myself (use the built-in version), but tin, the newsreader, comes with inews (inews.c) and one can (Cygwin) compile tin et al on/for Win32 (95/98/NT/2000/<whatever>). I do have tin itself on NT and give pointers/tips to/on that. syoder <syoder@parthus.com> wrote: > Is there a simple way to post to a NNTP server from a > MS-DOS command shell (Windows 98/NT/2000) or batch > file. > > How do I post a 'Hello World' message? > > Thanks, > > Stuart Yoder
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads