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) |
waitFor
public 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
IOException
ServerException
public Reply getLastReply()
public void close() throws IOException
IOException
public void waitFor(Flag aborted, int ioDelay, int maxWait) throws ServerException, IOException, InterruptedException
waitFor
in class BasicClientControlChannel
maxWait
- timeout in milisecondsioDelay
- frequency of polling the control channel
and checking the conditionsaborted
- flag indicating wait aborted.ServerException
IOException
InterruptedException
public Reply read() throws ServerException, IOException, FTPReplyParseException, EOFException
read
in class BasicClientControlChannel
IOException
- on I/O errorFTPReplyParseException
- on malformatted server replyServerException
EOFException
public void abortTransfer()
abortTransfer
in class BasicClientControlChannel
public void write(Command cmd) throws IOException, IllegalArgumentException
cmd
- FTP commandIOException
- on I/O errorIllegalArgumentException
public Reply exchange(Command cmd) throws ServerException, IOException, FTPReplyParseException
cmd
- FTP commandIOException
- on I/O errorFTPReplyParseException
- on bad reply formatServerException
public 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)ServerException
protected void writeln(String msg) throws IOException
IOException
protected void writeStr(String msg) throws IOException
IOException
protected boolean hasBeenOpened()
protected boolean haveStreams()
Copyright © 2016. All rights reserved.