ExtendedNNTPOpspublic class ExtendedNNTPOps extends Object Simple class showing some of the extended commands (AUTH, XOVER, LIST ACTIVE) |
Fields Summary |
---|
org.apache.commons.net.nntp.NNTPClient | client |
Constructors Summary |
---|
public ExtendedNNTPOps()
client = new NNTPClient();
client.addProtocolCommandListener(new PrintCommandListener(new PrintWriter(System.out)));
|
Methods Summary |
---|
public void | demo(java.lang.String host, java.lang.String user, java.lang.String password)
try {
client.connect(host);
// AUTHINFO USER/AUTHINFO PASS
boolean success = client.authenticate(user, password);
if (success) {
System.out.println("Authentication succeeded");
} else {
System.out.println("Authentication failed, error =" + client.getReplyString());
}
// XOVER
NewsgroupInfo testGroup = new NewsgroupInfo();
client.selectNewsgroup("alt.test", testGroup);
int lowArticleNumber = testGroup.getFirstArticle();
int highArticleNumber = lowArticleNumber + 100;
Article[] articles = NNTPUtils.getArticleInfo(client, lowArticleNumber, highArticleNumber);
for (int i = 0; i < articles.length; ++i) {
System.out.println(articles[i].getSubject());
}
// LIST ACTIVE
NewsgroupInfo[] fanGroups = client.listNewsgroups("alt.fan.*");
for (int i = 0; i < fanGroups.length; ++i) {
System.out.println(fanGroups[i].getNewsgroup());
}
} catch (IOException e) {
e.printStackTrace();
}
| public static void | main(java.lang.String[] args)
ExtendedNNTPOps ops;
if (args.length != 3) {
System.err.println("usage: ExtendedNNTPOps nntpserver username password");
System.exit(1);
}
ops = new ExtendedNNTPOps();
ops.demo(args[0], args[1], args[2]);
|
|