org.opennms.bb.dp.capsd.plugin
Class TestForFtpServer

java.lang.Object
  |
  +--org.opennms.bb.dp.capsd.plugin.TestForFtpServer
All Implemented Interfaces:
CapsdPlugin

public class TestForFtpServer
extends Object
implements CapsdPlugin

This class is designed to be used by the capabilities daemon to test for the existance of an FTP server on remote interfaces. The class implements the CapsdPlugin interface that allows it to be used along with other plugins by the daemon.

Version:
$Revision: 1.7 $
Author:
Sowmya, Weaver, OpenNMS

Field Summary
private static String CAPABILITY_NAME
          The capability name of the plugin.
private static int DEFAULT_PORT
          The port on which the host is checked to see if it supports FTP.
 
Constructor Summary
TestForFtpServer()
          The default constructor for the object.
 
Method Summary
 String getCapabilityName()
          Returns the capability name of the plugin poller.
private  String getLine(InputStream istream)
          Reads a single line at a time from the input stream.
 boolean isProtocolSupported(InetAddress host)
          Returns true if the host supports FTP.
 boolean isProtocolSupported(InetAddress host, int port)
          Returns true if the host supports FTP on the port specified.
 boolean isProtocolSupported(InetAddress host, int port, String capName)
          Returns true if the host supports FTP on the specified port and the capability specified is 'isFtp'
 boolean isProtocolSupported(InetAddress host, String capName)
          Returns true if the host supports the classes protocol.
private  boolean isServer(InetAddress host, int port)
          Test to see if the passed host-port pair is the endpoint for an FTP server.
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

DEFAULT_PORT

private static final int DEFAULT_PORT

The port on which the host is checked to see if it supports FTP.


CAPABILITY_NAME

private static final String CAPABILITY_NAME

The capability name of the plugin.

Constructor Detail

TestForFtpServer

public TestForFtpServer()

The default constructor for the object. There is currently no data to be initialized in the constructor. It is present for completeness.

Method Detail

getLine

private String getLine(InputStream istream)
                throws IOException

Reads a single line at a time from the input stream. Each line is terminated by the sequence '\r\n'. For more information on the format of the line see the FTP RFC.

If the end of file condition is reached before the cariage-return line-feed sequence then the received buffer is returned, or a string of zero length.

NOTE: The \r\n sequence is stripped from the returned line.

Parameters:
istream - The input stream from which characters are to be read.
Returns:
A line of characters read off the input stream.
Throws:
java.lang.IOException - Thrown if an error occurs reading the data from the stream.

isServer

private boolean isServer(InetAddress host,
                         int port)

Test to see if the passed host-port pair is the endpoint for an FTP server. If there is an FTP server at that destination then a value of true is returned from the method. Otherwise a false value is returned to the caller.

Parameters:
host - The remote host to connect to.
port - The remote port on the host.
Returns:
True if server supports FTP on the specified port, false otherwise

isProtocolSupported

public boolean isProtocolSupported(InetAddress host)

Returns true if the host supports FTP.

Specified by:
isProtocolSupported in interface CapsdPlugin
Parameters:
host - The InetAddress which is to be checked for FTP support
Returns:
True if the host supports FTP, false otherwise

isProtocolSupported

public boolean isProtocolSupported(InetAddress host,
                                   int port)

Returns true if the host supports FTP on the port specified.

Parameters:
host - The InetAddress which is to be checked for FTP support.
port - The port on which the FTP test is to be done.
Returns:
True if the host supports FTP, false otherwise.

isProtocolSupported

public boolean isProtocolSupported(InetAddress host,
                                   String capName)
                            throws UnsupportedProtocolException

Returns true if the host supports the classes protocol. If the protocl passed to the method is not supported by this instance the an exception is thrown to the caller.

Specified by:
isProtocolSupported in interface CapsdPlugin
Parameters:
host - The InetAddress which is to be checked for FTP support
capName - The capability whose suport is to be checked for
Returns:
True if the host supports FTP, false otherwise
Throws:
UnsupportedProtocolException - Thrown if capability specified is not supported by this instance.

isProtocolSupported

public boolean isProtocolSupported(InetAddress host,
                                   int port,
                                   String capName)
                            throws UnsupportedProtocolException

Returns true if the host supports FTP on the specified port and the capability specified is 'isFtp'

Parameters:
host - The InetAddress which is to be checked for FTP support
port - The port number to be used for the FTP support
capName - The capability whose suport is to be checked for
Returns:
True if the host supports FTP, false otherwise
Throws:
UnsupportedProtocolException - Thrown if capability specified is not supported by the instance.

getCapabilityName

public String getCapabilityName()

Returns the capability name of the plugin poller. In this instance it will be the string "isFTP".

Specified by:
getCapabilityName in interface CapsdPlugin
Returns:
The capability name.