public class FTPControlChannel extends BasicClientControlChannel
Represents FTP Protocol Interpreter. Encapsulates control channel communication.
| Modifier and Type | Field and Description |
|---|---|
static String |
CRLF |
protected BufferedReader |
ftpIn |
protected OutputStream |
ftpOut |
protected boolean |
hasBeenOpened |
protected String |
host |
protected int |
port |
protected InputStream |
rawFtpIn |
protected Socket |
socket |
| Constructor and Description |
|---|
FTPControlChannel(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) |
| Modifier and Type | Method and Description |
|---|---|
void |
abortTransfer() |
void |
close()
Closes the control channel
|
Reply |
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 BufferedReader |
getBufferedReader() |
String |
getHost() |
Reply |
getLastReply()
Returns the last reply received from the server.
|
protected 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(InputStream in) |
protected void |
setOutputStream(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(String msg) |
protected void |
writeStr(String msg) |
waitForpublic static final String CRLF
protected Socket socket
protected BufferedReader ftpIn
protected InputStream rawFtpIn
protected OutputStream ftpOut
protected String host
protected int port
protected boolean hasBeenOpened
public FTPControlChannel(String host, int port)
public FTPControlChannel(InputStream in, OutputStream out)
public String getHost()
public int getPort()
public boolean isIPv6()
protected BufferedReader getBufferedReader()
protected OutputStream getOutputStream()
protected void setInputStream(InputStream in)
protected void setOutputStream(OutputStream out)
public void open()
throws IOException,
ServerException
120
220
220
421
IOException - on I/O errorServerException - on negative or faulty server replyprotected void readInitialReplies()
throws IOException,
ServerException
IOExceptionServerExceptionpublic Reply getLastReply()
public void close()
throws IOException
IOExceptionpublic void waitFor(Flag aborted, int ioDelay, int maxWait) throws ServerException, IOException, InterruptedException
waitFor in class BasicClientControlChannelmaxWait - timeout in milisecondsioDelay - frequency of polling the control channel
and checking the conditionsaborted - flag indicating wait aborted.ServerExceptionIOExceptionInterruptedExceptionpublic Reply read() throws ServerException, IOException, FTPReplyParseException, EOFException
read in class BasicClientControlChannelIOException - on I/O errorFTPReplyParseException - on malformatted server replyServerExceptionEOFExceptionpublic void abortTransfer()
abortTransfer in class BasicClientControlChannelpublic void write(Command cmd) throws IOException, IllegalArgumentException
cmd - FTP commandIOException - on I/O errorIllegalArgumentExceptionpublic Reply exchange(Command cmd) throws ServerException, IOException, FTPReplyParseException
cmd - FTP commandIOException - on I/O errorFTPReplyParseException - on bad reply formatServerExceptionpublic Reply execute(Command cmd) throws ServerException, IOException, FTPReplyParseException, UnexpectedReplyCodeException
cmd - FTP commandIOException - on I/O errorFTPReplyParseException - on bad reply formatUnexpectedReplyCodeException - if reply is not a positive
completion reply (code 200)ServerExceptionprotected void writeln(String msg) throws IOException
IOExceptionprotected void writeStr(String msg) throws IOException
IOExceptionprotected boolean hasBeenOpened()
protected boolean haveStreams()
Copyright © 2015. All rights reserved.