Package org.apache.commons.net.nntp

Examples of org.apache.commons.net.nntp.NNTPClient


        String hostname = args[0];
        String newsgroup = args[1];
        // Article specifier can be numeric or Id in form <m.n.o.x@host>
        String articleSpec = args.length >= 3 ? args[2] : null;

        NNTPClient client = new NNTPClient();
        client.addProtocolCommandListener(new PrintCommandListener(new PrintWriter(System.out), true));
        client.connect(hostname);

        if (args.length == 5) { // Optional auth
            String user = args[3];
            String password = args[4];
            if(!client.authenticate(user, password)) {
                System.out.println("Authentication failed for user " + user + "!");
                System.exit(1);
            }
        }

        NewsgroupInfo group = new NewsgroupInfo();
        client.selectNewsgroup(newsgroup, group);

        BufferedReader br;
        String line;
        if (articleSpec != null) {
            br = (BufferedReader) client.retrieveArticleHeader(articleSpec);
        } else {
            long articleNum = group.getLastArticleLong();
            br = client.retrieveArticleHeader(articleNum);
        }
        if (br != null) {
            while((line=br.readLine()) != null) {
                System.out.println(line);
            }
            br.close();
        }
        if (articleSpec != null) {
            br = (BufferedReader) client.retrieveArticleBody(articleSpec);
        } else {
            long articleNum = group.getLastArticleLong();
            br = client.retrieveArticleBody(articleNum);
        }
        if (br != null) {
            while((line=br.readLine()) != null) {
                System.out.println(line);
            }
View Full Code Here


        if (this.retryCounterArray == null) {
            this.retryCounterArray = new int[numNodes];
        }

        this.nntpClient = new NNTPClient();

        // Limit the time to wait on a socket.
        try {
            this.nntpClient.setDefaultTimeout(DEFAULT_SOCKET_TIMEOUT_MS);
        }
View Full Code Here

       
        String hostname = args[0];
        String user = args[1];
        String password = args[2];
       
        NNTPClient client = new NNTPClient();
        client.addProtocolCommandListener(new PrintCommandListener(new PrintWriter(System.out)));
        client.connect(hostname);
//      optional authentication
//       
//        if(!client.authenticate(user, password)) {
//            System.out.println("Authentication failed for user " + user + "!");
//          //  System.exit(1);
//        }
//       
        NewsgroupInfo group = new NewsgroupInfo();
        client.selectNewsgroup("alt.test", group);
       
        long lowArticleNumber = group.getFirstArticle();
        long highArticleNumber = lowArticleNumber + 5000;
       
        System.out.println("Retrieving articles between [" + lowArticleNumber + "] and [" + highArticleNumber + "]");
View Full Code Here

        String from, subject, newsgroup, filename, server, organization;
        String references;
        BufferedReader stdin;
        FileReader fileReader = null;
        SimpleNNTPHeader header;
        NNTPClient client;

        if (args.length < 1)
        {
            System.err.println("Usage: post newsserver");
            System.exit(1);
        }

        server = args[0];

        stdin = new BufferedReader(new InputStreamReader(System.in));

        try
        {
            System.out.print("From: ");
            System.out.flush();

            from = stdin.readLine();

            System.out.print("Subject: ");
            System.out.flush();

            subject = stdin.readLine();

            header = new SimpleNNTPHeader(from, subject);

            System.out.print("Newsgroup: ");
            System.out.flush();

            newsgroup = stdin.readLine();
            header.addNewsgroup(newsgroup);

            while (true)
            {
                System.out.print("Additional Newsgroup <Hit enter to end>: ");
                System.out.flush();

                // Of course you don't want to do this because readLine() may be null
                newsgroup = stdin.readLine().trim();

                if (newsgroup.length() == 0)
                    break;

                header.addNewsgroup(newsgroup);
            }

            System.out.print("Organization: ");
            System.out.flush();

            organization = stdin.readLine();

            System.out.print("References: ");
            System.out.flush();

            references = stdin.readLine();

            if (organization != null && organization.length() > 0)
                header.addHeaderField("Organization", organization);

            if (references != null && organization.length() > 0)
                header.addHeaderField("References", references);

            header.addHeaderField("X-Newsreader", "NetComponents");

            System.out.print("Filename: ");
            System.out.flush();

            filename = stdin.readLine();

            try
            {
                fileReader = new FileReader(filename);
            }
            catch (FileNotFoundException e)
            {
                System.err.println("File not found. " + e.getMessage());
                System.exit(1);
            }

            client = new NNTPClient();
            client.addProtocolCommandListener(new PrintCommandListener(
                                                  new PrintWriter(System.out)));

            client.connect(server);

            if (!NNTPReply.isPositiveCompletion(client.getReplyCode()))
            {
                client.disconnect();
                System.err.println("NNTP server refused connection.");
                System.exit(1);
            }

            if (client.isAllowedToPost())
            {
                Writer writer = client.postArticle();

                if (writer != null)
                {
                    writer.write(header.toString());
                    Util.copyReader(fileReader, writer);
                    writer.close();
                    client.completePendingCommand();
                }
            }

            fileReader.close();

            client.logout();

            client.disconnect();
        }
        catch (IOException e)
        {
            e.printStackTrace();
            System.exit(1);
View Full Code Here

   
    NNTPClient client;

    public ExtendedNNTPOps() {
        client = new NNTPClient();
        client.addProtocolCommandListener(new PrintCommandListener(new PrintWriter(System.out)));
    }
View Full Code Here

public final class ListNewsgroups
{

    public final static void main(String[] args)
    {
        NNTPClient client;
        NewsgroupInfo[] list;

        if (args.length < 1)
        {
            System.err.println("Usage: newsgroups newsserver");
            System.exit(1);
        }

        client = new NNTPClient();

        try
        {
            client.connect(args[0]);

            list = client.listNewsgroups();

            if (list != null)
            {
                for (int i = 0; i < list.length; i++)
                    System.out.println(list[i].getNewsgroup());
            }
            else
            {
                System.err.println("LIST command failed.");
                System.err.println("Server reply: " + client.getReplyString());
            }
        }
        catch (IOException e)
        {
            e.printStackTrace();
        }
        finally
        {
            try
            {
                if (client.isConnected())
                    client.disconnect();
            }
            catch (IOException e)
            {
                System.err.println("Error disconnecting from server.");
                e.printStackTrace();
View Full Code Here

TOP

Related Classes of org.apache.commons.net.nntp.NNTPClient

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.