Package org.globus.ftp.vanilla
Class FTPControlChannel
- java.lang.Object
-
- org.globus.ftp.vanilla.BasicClientControlChannel
-
- org.globus.ftp.vanilla.FTPControlChannel
-
- Direct Known Subclasses:
GridFTPControlChannel
public class FTPControlChannel extends BasicClientControlChannel
Represents FTP Protocol Interpreter. Encapsulates control channel communication.
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
CRLF
protected java.io.BufferedReader
ftpIn
protected java.io.OutputStream
ftpOut
protected boolean
hasBeenOpened
protected java.lang.String
host
private boolean
ipv6
private Reply
lastReply
private static org.apache.commons.logging.Log
logger
protected int
port
protected java.io.InputStream
rawFtpIn
protected java.net.Socket
socket
private static int
WAIT_FOREVER
-
Constructor Summary
Constructors Constructor Description FTPControlChannel(java.io.InputStream in, java.io.OutputStream out)
Using this constructor, you can initialize an instance that does not talk directly to the socket.FTPControlChannel(java.lang.String host, int port)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
abortTransfer()
private int
checkSocketDone(Flag aborted, int ioDelay, int maxWait)
void
close()
Closes the control channelReply
exchange(Command cmd)
Write the command to the control channel, block until reply arrives and return the reply.Reply
execute(Command cmd)
Write the command to the control channel, block until reply arrives and check if the command completed successfully (reply code 200).protected java.io.BufferedReader
getBufferedReader()
java.lang.String
getHost()
Reply
getLastReply()
Returns the last reply received from the server.protected java.io.OutputStream
getOutputStream()
int
getPort()
protected boolean
hasBeenOpened()
protected boolean
haveStreams()
boolean
isIPv6()
void
open()
opens the connection and returns after it is ready for communication.Reply
read()
Block until a reply is available in the control channel.protected void
readInitialReplies()
protected void
setInputStream(java.io.InputStream in)
protected void
setOutputStream(java.io.OutputStream out)
void
waitFor(Flag aborted, int ioDelay, int maxWait)
Block until one of the conditions are true: a reply is available in the control channel, timeout (maxWait) expired aborted flag changes to true.void
write(Command cmd)
Sends the command over the control channel.protected void
writeln(java.lang.String msg)
protected void
writeStr(java.lang.String msg)
-
Methods inherited from class org.globus.ftp.vanilla.BasicClientControlChannel
waitFor
-
-
-
-
Field Detail
-
logger
private static org.apache.commons.logging.Log logger
-
CRLF
public static final java.lang.String CRLF
- See Also:
- Constant Field Values
-
WAIT_FOREVER
private static final int WAIT_FOREVER
- See Also:
- Constant Field Values
-
socket
protected java.net.Socket socket
-
ftpIn
protected java.io.BufferedReader ftpIn
-
rawFtpIn
protected java.io.InputStream rawFtpIn
-
ftpOut
protected java.io.OutputStream ftpOut
-
host
protected java.lang.String host
-
port
protected int port
-
hasBeenOpened
protected boolean hasBeenOpened
-
ipv6
private boolean ipv6
-
lastReply
private Reply lastReply
-
-
Constructor Detail
-
FTPControlChannel
public FTPControlChannel(java.lang.String host, int port)
-
FTPControlChannel
public FTPControlChannel(java.io.InputStream in, java.io.OutputStream out)
Using this constructor, you can initialize an instance that does not talk directly to the socket. If you use this constructor using streams that belong to an active connection, there's no need to call open() afterwards.
-
-
Method Detail
-
getHost
public java.lang.String getHost()
-
getPort
public int getPort()
-
isIPv6
public boolean isIPv6()
-
getBufferedReader
protected java.io.BufferedReader getBufferedReader()
-
getOutputStream
protected java.io.OutputStream getOutputStream()
-
setInputStream
protected void setInputStream(java.io.InputStream in)
-
setOutputStream
protected void setOutputStream(java.io.OutputStream out)
-
open
public void open() throws java.io.IOException, ServerException
opens the connection and returns after it is ready for communication. Before returning, it intercepts the initial server reply(-ies), and not positive, throws UnexpectedReplyCodeException. After returning, there should be no more queued replies on the line. Here's the sequence for connection establishment (rfc959):120 220 220 421
- Throws:
java.io.IOException
- on I/O errorServerException
- on negative or faulty server reply
-
readInitialReplies
protected void readInitialReplies() throws java.io.IOException, ServerException
- Throws:
java.io.IOException
ServerException
-
getLastReply
public Reply getLastReply()
Returns the last reply received from the server.
-
close
public void close() throws java.io.IOException
Closes the control channel- Throws:
java.io.IOException
-
checkSocketDone
private int checkSocketDone(Flag aborted, int ioDelay, int maxWait) throws ServerException, java.io.IOException, java.lang.InterruptedException
- Throws:
ServerException
java.io.IOException
java.lang.InterruptedException
-
waitFor
public void waitFor(Flag aborted, int ioDelay, int maxWait) throws ServerException, java.io.IOException, java.lang.InterruptedException
Block until one of the conditions are true:- a reply is available in the control channel,
- timeout (maxWait) expired
- aborted flag changes to true.
- Specified by:
waitFor
in classBasicClientControlChannel
- Parameters:
maxWait
- timeout in milisecondsioDelay
- frequency of polling the control channel and checking the conditionsaborted
- flag indicating wait aborted.- Throws:
ServerException
java.io.IOException
java.lang.InterruptedException
-
read
public Reply read() throws ServerException, java.io.IOException, FTPReplyParseException, java.io.EOFException
Block until a reply is available in the control channel.- Specified by:
read
in classBasicClientControlChannel
- Returns:
- the first unread reply from the control channel.
- Throws:
java.io.IOException
- on I/O errorFTPReplyParseException
- on malformatted server replyServerException
java.io.EOFException
-
abortTransfer
public void abortTransfer()
- Specified by:
abortTransfer
in classBasicClientControlChannel
-
write
public void write(Command cmd) throws java.io.IOException, java.lang.IllegalArgumentException
Sends the command over the control channel. Do not wait for reply.- Parameters:
cmd
- FTP command- Throws:
java.io.IOException
- on I/O errorjava.lang.IllegalArgumentException
-
exchange
public Reply exchange(Command cmd) throws ServerException, java.io.IOException, FTPReplyParseException
Write the command to the control channel, block until reply arrives and return the reply. Before calling this method make sure that no old replies are waiting on the control channel. Otherwise the reply returned may not be the reply to this command.- Parameters:
cmd
- FTP command- Returns:
- the first reply that waits in the control channel
- Throws:
java.io.IOException
- on I/O errorFTPReplyParseException
- on bad reply formatServerException
-
execute
public Reply execute(Command cmd) throws ServerException, java.io.IOException, FTPReplyParseException, UnexpectedReplyCodeException
Write the command to the control channel, block until reply arrives and check if the command completed successfully (reply code 200). If so, return the reply, otherwise throw exception. Before calling this method make sure that no old replies are waiting on the control channel. Otherwise the reply returned may not be the reply to this command.- Parameters:
cmd
- FTP command- Returns:
- the first reply that waits in the control channel
- Throws:
java.io.IOException
- on I/O errorFTPReplyParseException
- on bad reply formatUnexpectedReplyCodeException
- if reply is not a positive completion reply (code 200)ServerException
-
writeln
protected void writeln(java.lang.String msg) throws java.io.IOException
- Throws:
java.io.IOException
-
writeStr
protected void writeStr(java.lang.String msg) throws java.io.IOException
- Throws:
java.io.IOException
-
hasBeenOpened
protected boolean hasBeenOpened()
-
haveStreams
protected boolean haveStreams()
-
-