Class FTPControlChannel
java.lang.Object
org.globus.ftp.vanilla.BasicClientControlChannel
org.globus.ftp.vanilla.FTPControlChannel
- Direct Known Subclasses:
GridFTPControlChannel
Represents FTP Protocol Interpreter. Encapsulates control channel communication.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Stringprotected BufferedReaderprotected OutputStreamprotected booleanprotected Stringprivate booleanprivate Replyprivate static org.apache.commons.logging.Logprotected intprotected InputStreamprotected Socketprivate static final int -
Constructor Summary
ConstructorsConstructorDescriptionFTPControlChannel(InputStream in, OutputStream out) Using this constructor, you can initialize an instance that does not talk directly to the socket.FTPControlChannel(String host, int port) -
Method Summary
Modifier and TypeMethodDescriptionvoidprivate intcheckSocketDone(Flag aborted, int ioDelay, int maxWait) voidclose()Closes the control channelWrite the command to the control channel, block until reply arrives and return the reply.Write the command to the control channel, block until reply arrives and check if the command completed successfully (reply code 200).protected BufferedReadergetHost()Returns the last reply received from the server.protected OutputStreamintgetPort()protected booleanprotected booleanbooleanisIPv6()voidopen()opens the connection and returns after it is ready for communication.read()Block until a reply is available in the control channel.protected voidprotected voidprotected voidvoidBlock until one of the conditions are true: a reply is available in the control channel, timeout (maxWait) expired aborted flag changes to true.voidSends the command over the control channel.protected voidprotected voidMethods inherited from class BasicClientControlChannel
waitFor
-
Field Details
-
logger
private static org.apache.commons.logging.Log logger -
CRLF
- See Also:
-
WAIT_FOREVER
private static final int WAIT_FOREVER- See Also:
-
socket
-
ftpIn
-
rawFtpIn
-
ftpOut
-
host
-
port
protected int port -
hasBeenOpened
protected boolean hasBeenOpened -
ipv6
private boolean ipv6 -
lastReply
-
-
Constructor Details
-
FTPControlChannel
-
FTPControlChannel
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 Details
-
getHost
-
getPort
public int getPort() -
isIPv6
public boolean isIPv6() -
getBufferedReader
-
getOutputStream
-
setInputStream
-
setOutputStream
-
open
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:
IOException- on I/O errorServerException- on negative or faulty server reply
-
readInitialReplies
- Throws:
IOExceptionServerException
-
getLastReply
Returns the last reply received from the server. -
close
-
checkSocketDone
private int checkSocketDone(Flag aborted, int ioDelay, int maxWait) throws ServerException, IOException, InterruptedException -
waitFor
public void waitFor(Flag aborted, int ioDelay, int maxWait) throws ServerException, IOException, 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:
waitForin classBasicClientControlChannel- Parameters:
aborted- flag indicating wait aborted.ioDelay- frequency of polling the control channel and checking the conditionsmaxWait- timeout in miliseconds- Throws:
ServerExceptionIOExceptionInterruptedException
-
read
Block until a reply is available in the control channel.- Specified by:
readin classBasicClientControlChannel- Returns:
- the first unread reply from the control channel.
- Throws:
IOException- on I/O errorFTPReplyParseException- on malformatted server replyServerExceptionEOFException
-
abortTransfer
public void abortTransfer()- Specified by:
abortTransferin classBasicClientControlChannel
-
write
Sends the command over the control channel. Do not wait for reply.- Parameters:
cmd- FTP command- Throws:
IOException- on I/O errorIllegalArgumentException
-
exchange
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:
IOException- on I/O errorFTPReplyParseException- on bad reply formatServerException
-
execute
public Reply execute(Command cmd) throws ServerException, 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:
IOException- on I/O errorFTPReplyParseException- on bad reply formatUnexpectedReplyCodeException- if reply is not a positive completion reply (code 200)ServerException
-
writeln
- Throws:
IOException
-
writeStr
- Throws:
IOException
-
hasBeenOpened
protected boolean hasBeenOpened() -
haveStreams
protected boolean haveStreams()
-