org.metastatic.rsync.v2
Class SocketClient

java.lang.Object
  |
  +--org.metastatic.rsync.v2.SocketClient
All Implemented Interfaces:
Constants

public class SocketClient
extends Object
implements Constants

A SocketClient connects to rsync servers over TCP port 873. This version of SocketClient connects in the same fashion as rsync-2.* series clients, using protocol version 26.


Field Summary
protected  boolean authReqd
          Whether or not the server wants authorization.
protected  String challenge
          The server's authentication challenge.
protected  boolean connected
          Our connection status.
protected  String error
           
protected  InputStream in
          Our input stream from the server.
static int MIN_PROTOCOL_VERSION
          The minimum protocol version we support.
protected  LinkedList modules
          The modules available on the server.
protected  OutputStream out
          Our output stream to the server.
static int PROTOCOL_VERSION
          The protocol version we conform to.
protected  int remoteVersion
          The server's protocol version.
protected  LinkedList serverMessages
          The raw list of server messages, possibly the MOTD and the module list.
protected  String serverMOTD
          The server's message-of-the-day.
protected  Socket socket
          The socket connected to the remote server.
 
Fields inherited from interface org.metastatic.rsync.v2.Constants
_S_IFDIR, _S_IFLNK, _S_IFMT, _S_IFREG, AT_ERROR, BLOCK_LENGTH, CHUNK_SIZE, FLAG_DELETE, FLIST_RECEIVE_DONE, FLIST_RECEIVE_FILES, FLIST_RECEIVE_GIDS, FLIST_RECEIVE_UIDS, FLIST_SEND_DONE, FLIST_SEND_FILES, FLIST_SEND_GIDS, FLIST_SEND_UIDS, INPUT_MASK, LONG_NAME, MAX_PROTOCOL_VERSION, MAXPATHLEN, OUTPUT_MASK, RECV_RECEIVE_DELTAS, RECV_RECEIVE_INDEX, RECV_SEND_INDEX, RECV_SEND_SUMS, RECV_WAIT, RSYNCD_AUTHREQD, RSYNCD_EXIT, RSYNCD_GREETING, RSYNCD_OK, RSYNCD_PORT, SAME_DIR, SAME_GID, SAME_MODE, SAME_NAME, SAME_RDEV, SAME_TIME, SAME_UID, SENDER_DONE, SENDER_RECEIVE_INDEX, SENDER_RECEIVE_SUMS, SENDER_SEND_DELTAS, SENDER_SEND_FILE, SENDER_WAIT, SETUP_READ_AUTH, SETUP_READ_DONE, SETUP_READ_GREETING, SETUP_READ_MODULE, SETUP_READ_OPTIONS, SETUP_WRITE_CHALLENGE, SETUP_WRITE_DONE, SETUP_WRITE_ERROR, SETUP_WRITE_GREETING, SETUP_WRITE_MODULES, SETUP_WRITE_OK, SETUP_WRITE_WAIT, STATE_DONE, STATE_INPUT_DONE, STATE_OUTPUT_DONE, STATE_RECEIVE_EXCLUDE, STATE_RECEIVE_FLIST, STATE_RECEIVER, STATE_RECEIVER_INPUT, STATE_RECEIVER_OUTPUT, STATE_SEND_FLIST, STATE_SENDER, STATE_SENDER_INPUT, STATE_SENDER_OUTPUT, STATE_SETUP_PROTOCOL, SUM_LENGTH, URL_PREFIX
 
Constructor Summary
protected SocketClient(Socket socket, InputStream in, OutputStream out)
          This class cannot be directly instatiated.
 
Method Summary
 boolean authenticate(String user, String pass)
          Authenticate the user to the server.
 boolean authRequired()
          Test if authentication is required.
static SocketClient connect(String host, int port, String module)
          Connect to host over port, asking for module.
static SocketClient connect(String host, String module)
          Connect to host over port 873, asking for module.
 boolean connected()
          See if we are connected.
 String getError()
          Get the last error message the server reported.
 List getServerMessages()
          Get the messages the server sends during connection.
 void serverArgs(String[] sargv)
          Send the "server args".
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

socket

protected Socket socket
The socket connected to the remote server.


in

protected InputStream in
Our input stream from the server.


out

protected OutputStream out
Our output stream to the server.


serverMOTD

protected String serverMOTD
The server's message-of-the-day.


modules

protected LinkedList modules
The modules available on the server.


serverMessages

protected LinkedList serverMessages
The raw list of server messages, possibly the MOTD and the module list.


connected

protected boolean connected
Our connection status.


remoteVersion

protected int remoteVersion
The server's protocol version.


authReqd

protected boolean authReqd
Whether or not the server wants authorization.


challenge

protected String challenge
The server's authentication challenge.


error

protected String error

PROTOCOL_VERSION

public static final int PROTOCOL_VERSION
The protocol version we conform to.

See Also:
Constant Field Values

MIN_PROTOCOL_VERSION

public static final int MIN_PROTOCOL_VERSION
The minimum protocol version we support.

See Also:
Constant Field Values
Constructor Detail

SocketClient

protected SocketClient(Socket socket,
                       InputStream in,
                       OutputStream out)
This class cannot be directly instatiated. Use either connect(java.lang.String,java.lang.String) or connect(java.lang.String,int,java.lang.String).

Method Detail

connect

public static SocketClient connect(String host,
                                   String module)
                            throws IOException
Connect to host over port 873, asking for module.

Parameters:
host - The host to connect to.
module - The module to use on the host, or can be either null or "#list" to fetch a listing of modules.
Returns:
A new SocketClient.
IOException

connect

public static SocketClient connect(String host,
                                   int port,
                                   String module)
                            throws IOException
Connect to host over port, asking for module.

Parameters:
host - The host to connect to.
port - The port to connect to.
module - The module to use on the host, or can be either null or "#list" to fetch a listing of modules.
Returns:
A new SocketClient.
IOException

connected

public boolean connected()
See if we are connected. There is no way to terminate the connection if we are the client during this initial phase; the server ends the session only if we send an erronous module name,

Returns:
true If we are connected.

getServerMessages

public List getServerMessages()
Get the messages the server sends during connection. This includes the message-of-the-day, and possibly a listing of available modules.

Returns:
The server's messages, in order.

authRequired

public boolean authRequired()
Test if authentication is required. A Rsync object cannot be obtained if this method returns true.


authenticate

public boolean authenticate(String user,
                            String pass)
                     throws IOException
Authenticate the user to the server.

Parameters:
user - The username.
pass - The password.
Returns:
true If authentication succeeds. The connection will be closed if this method returns false.
IOException

getError

public String getError()
Get the last error message the server reported.

Returns:
The last error message.

serverArgs

public void serverArgs(String[] sargv)
                throws IOException
Send the "server args".

Parameters:
sargv - The server args.
IOException