Methods Summary |
---|
private void | __getReply()
int length;
_newReplyString = true;
_replyLines.setSize(0);
String line = _controlInput.readLine();
if (line == null)
throw new FTPConnectionClosedException(
"Connection closed without indication.");
// In case we run into an anomaly we don't want fatal index exceptions
// to be thrown.
length = line.length();
if (length < 3)
throw new MalformedServerReplyException(
"Truncated server reply: " + line);
try
{
String code = line.substring(0, 3);
_replyCode = Integer.parseInt(code);
}
catch (NumberFormatException e)
{
throw new MalformedServerReplyException(
"Could not parse response code.\nServer Reply: " + line);
}
_replyLines.addElement(line);
// Get extra lines if message continues.
if (length > 3 && line.charAt(3) == '-")
{
do
{
line = _controlInput.readLine();
if (line == null)
throw new FTPConnectionClosedException(
"Connection closed without indication.");
_replyLines.addElement(line);
// The length() check handles problems that could arise from readLine()
// returning too soon after encountering a naked CR or some other
// anomaly.
}
while (!(line.length() >= 4 && line.charAt(3) != '-" &&
Character.isDigit(line.charAt(0))));
// This is too strong a condition because of non-conforming ftp
// servers like ftp.funet.fi which sent 226 as the last line of a
// 426 multi-line reply in response to ls /. We relax the condition to
// test that the line starts with a digit rather than starting with
// the code.
// line.startsWith(code)));
}
if (_commandSupport_.getListenerCount() > 0)
_commandSupport_.fireReplyReceived(_replyCode, getReplyString());
if (_replyCode == FTPReply.SERVICE_NOT_AVAILABLE)
throw new FTPConnectionClosedException(
"FTP response 421 received. Server closed connection.");
|
protected void | _connectAction_()
super._connectAction_();
_controlInput =
new BufferedReader(new InputStreamReader(getInputStream(),
getControlEncoding()));
_controlOutput =
new BufferedWriter(new OutputStreamWriter(getOutputStream(),
getControlEncoding()));
__getReply();
// If we received code 120, we have to fetch completion reply.
if (FTPReply.isPositivePreliminary(_replyCode))
__getReply();
|
public int | abor()A convenience method to send the FTP ABOR command to the server,
receive the reply, and return the reply code.
return sendCommand(FTPCommand.ABOR);
|
public int | acct(java.lang.String account)A convenience method to send the FTP ACCT command to the server,
receive the reply, and return the reply code.
return sendCommand(FTPCommand.ACCT, account);
|
public void | addProtocolCommandListener(org.apache.commons.net.ProtocolCommandListener listener)Adds a ProtocolCommandListener. Delegates this task to
{@link #_commandSupport_ _commandSupport_ }.
_commandSupport_.addProtocolCommandListener(listener);
|
public int | allo(int bytes)A convenience method to send the FTP ALLO command to the server,
receive the reply, and return the reply code.
return sendCommand(FTPCommand.ALLO, Integer.toString(bytes));
|
public int | allo(int bytes, int recordSize)A convenience method to send the FTP ALLO command to the server,
receive the reply, and return the reply code.
return sendCommand(FTPCommand.ALLO, Integer.toString(bytes) + " R " +
Integer.toString(recordSize));
|
public int | appe(java.lang.String pathname)A convenience method to send the FTP APPE command to the server,
receive the reply, and return the reply code. Remember, it is up
to you to manage the data connection. If you don't need this low
level of access, use {@link org.apache.commons.net.ftp.FTPClient}
, which will handle all low level details for you.
return sendCommand(FTPCommand.APPE, pathname);
|
public int | cdup()A convenience method to send the FTP CDUP command to the server,
receive the reply, and return the reply code.
return sendCommand(FTPCommand.CDUP);
|
public int | cwd(java.lang.String directory)A convenience method to send the FTP CWD command to the server,
receive the reply, and return the reply code.
return sendCommand(FTPCommand.CWD, directory);
|
public int | dele(java.lang.String pathname)A convenience method to send the FTP DELE command to the server,
receive the reply, and return the reply code.
return sendCommand(FTPCommand.DELE, pathname);
|
public void | disconnect()Closes the control connection to the FTP server and sets to null
some internal data so that the memory may be reclaimed by the
garbage collector. The reply text and code information from the
last command is voided so that the memory it used may be reclaimed.
super.disconnect();
_controlInput = null;
_controlOutput = null;
_replyLines.setSize(0);
_newReplyString = false;
_replyString = null;
|
public java.lang.String | getControlEncoding()
return _controlEncoding;
|
public int | getReply()Fetches a reply from the FTP server and returns the integer reply
code. After calling this method, the actual reply text can be accessed
from either calling {@link #getReplyString getReplyString } or
{@link #getReplyStrings getReplyStrings }. Only use this
method if you are implementing your own FTP client or if you need to
fetch a secondary response from the FTP server.
__getReply();
return _replyCode;
|
public int | getReplyCode()Returns the integer value of the reply code of the last FTP reply.
You will usually only use this method after you connect to the
FTP server to check that the connection was successful since
connect is of type void.
return _replyCode;
|
public java.lang.String | getReplyString()Returns the entire text of the last FTP server response exactly
as it was received, including all end of line markers in NETASCII
format.
Enumeration en;
StringBuffer buffer;
if (!_newReplyString)
return _replyString;
buffer = new StringBuffer(256);
en = _replyLines.elements();
while (en.hasMoreElements())
{
buffer.append((String)en.nextElement());
buffer.append(SocketClient.NETASCII_EOL);
}
_newReplyString = false;
return (_replyString = buffer.toString());
|
public java.lang.String[] | getReplyStrings()Returns the lines of text from the last FTP server response as an array
of strings, one entry per line. The end of line markers of each are
stripped from each line.
String[] lines;
lines = new String[_replyLines.size()];
_replyLines.copyInto(lines);
return lines;
|
public int | help()A convenience method to send the FTP HELP command to the server,
receive the reply, and return the reply code.
return sendCommand(FTPCommand.HELP);
|
public int | help(java.lang.String command)A convenience method to send the FTP HELP command to the server,
receive the reply, and return the reply code.
return sendCommand(FTPCommand.HELP, command);
|
public int | list()A convenience method to send the FTP LIST command to the server,
receive the reply, and return the reply code. Remember, it is up
to you to manage the data connection. If you don't need this low
level of access, use {@link org.apache.commons.net.ftp.FTPClient}
, which will handle all low level details for you.
return sendCommand(FTPCommand.LIST);
|
public int | list(java.lang.String pathname)A convenience method to send the FTP LIST command to the server,
receive the reply, and return the reply code. Remember, it is up
to you to manage the data connection. If you don't need this low
level of access, use {@link org.apache.commons.net.ftp.FTPClient}
, which will handle all low level details for you.
return sendCommand(FTPCommand.LIST, pathname);
|
public int | mkd(java.lang.String pathname)A convenience method to send the FTP MKD command to the server,
receive the reply, and return the reply code.
return sendCommand(FTPCommand.MKD, pathname);
|
public int | mode(int mode)A convenience method to send the FTP MODE command to the server,
receive the reply, and return the reply code.
return sendCommand(FTPCommand.MODE,
__modes.substring(mode, mode + 1));
|
public int | nlst()A convenience method to send the FTP NLST command to the server,
receive the reply, and return the reply code. Remember, it is up
to you to manage the data connection. If you don't need this low
level of access, use {@link org.apache.commons.net.ftp.FTPClient}
, which will handle all low level details for you.
return sendCommand(FTPCommand.NLST);
|
public int | nlst(java.lang.String pathname)A convenience method to send the FTP NLST command to the server,
receive the reply, and return the reply code. Remember, it is up
to you to manage the data connection. If you don't need this low
level of access, use {@link org.apache.commons.net.ftp.FTPClient}
, which will handle all low level details for you.
return sendCommand(FTPCommand.NLST, pathname);
|
public int | noop()A convenience method to send the FTP NOOP command to the server,
receive the reply, and return the reply code.
return sendCommand(FTPCommand.NOOP);
|
public int | pass(java.lang.String password)A convenience method to send the FTP PASS command to the server,
receive the reply, and return the reply code.
return sendCommand(FTPCommand.PASS, password);
|
public int | pasv()A convenience method to send the FTP PASV command to the server,
receive the reply, and return the reply code. Remember, it's up
to you to interpret the reply string containing the host/port
information.
return sendCommand(FTPCommand.PASV);
|
public int | port(java.net.InetAddress host, int port)A convenience method to send the FTP PORT command to the server,
receive the reply, and return the reply code.
int num;
StringBuffer info = new StringBuffer(24);
info.append(host.getHostAddress().replace('.", ',"));
num = port >>> 8;
info.append(',");
info.append(num);
info.append(',");
num = port & 0xff;
info.append(num);
return sendCommand(FTPCommand.PORT, info.toString());
|
public int | pwd()A convenience method to send the FTP PWD command to the server,
receive the reply, and return the reply code.
return sendCommand(FTPCommand.PWD);
|
public int | quit()A convenience method to send the FTP QUIT command to the server,
receive the reply, and return the reply code.
return sendCommand(FTPCommand.QUIT);
|
public int | rein()A convenience method to send the FTP REIN command to the server,
receive the reply, and return the reply code.
return sendCommand(FTPCommand.REIN);
|
public void | removeProtocolCommandListener(org.apache.commons.net.ProtocolCommandListener listener)Removes a ProtocolCommandListener. Delegates this task to
{@link #_commandSupport_ _commandSupport_ }.
_commandSupport_.removeProtocolCommandListener(listener);
|
public int | rest(java.lang.String marker)A convenience method to send the FTP REST command to the server,
receive the reply, and return the reply code.
return sendCommand(FTPCommand.REST, marker);
|
public int | retr(java.lang.String pathname)A convenience method to send the FTP RETR command to the server,
receive the reply, and return the reply code. Remember, it is up
to you to manage the data connection. If you don't need this low
level of access, use {@link org.apache.commons.net.ftp.FTPClient}
, which will handle all low level details for you.
return sendCommand(FTPCommand.RETR, pathname);
|
public int | rmd(java.lang.String pathname)A convenience method to send the FTP RMD command to the server,
receive the reply, and return the reply code.
return sendCommand(FTPCommand.RMD, pathname);
|
public int | rnfr(java.lang.String pathname)A convenience method to send the FTP RNFR command to the server,
receive the reply, and return the reply code.
return sendCommand(FTPCommand.RNFR, pathname);
|
public int | rnto(java.lang.String pathname)A convenience method to send the FTP RNTO command to the server,
receive the reply, and return the reply code.
return sendCommand(FTPCommand.RNTO, pathname);
|
public int | sendCommand(int command, java.lang.String args)Sends an FTP command to the server, waits for a reply and returns the
numerical response code. After invocation, for more detailed
information, the actual reply text can be accessed by calling
{@link #getReplyString getReplyString } or
{@link #getReplyStrings getReplyStrings }.
return sendCommand(FTPCommand._commands[command], args);
|
public int | sendCommand(java.lang.String command)Sends an FTP command with no arguments to the server, waits for a
reply and returns the numerical response code. After invocation, for
more detailed information, the actual reply text can be accessed by
calling {@link #getReplyString getReplyString } or
{@link #getReplyStrings getReplyStrings }.
return sendCommand(command, null);
|
public int | sendCommand(int command)Sends an FTP command with no arguments to the server, waits for a
reply and returns the numerical response code. After invocation, for
more detailed information, the actual reply text can be accessed by
calling {@link #getReplyString getReplyString } or
{@link #getReplyStrings getReplyStrings }.
return sendCommand(command, null);
|
public int | sendCommand(java.lang.String command, java.lang.String args)Sends an FTP command to the server, waits for a reply and returns the
numerical response code. After invocation, for more detailed
information, the actual reply text can be accessed by calling
{@link #getReplyString getReplyString } or
{@link #getReplyStrings getReplyStrings }.
String message;
__commandBuffer.setLength(0);
__commandBuffer.append(command);
if (args != null)
{
__commandBuffer.append(' ");
__commandBuffer.append(args);
}
__commandBuffer.append(SocketClient.NETASCII_EOL);
try{
_controlOutput.write(message = __commandBuffer.toString());
_controlOutput.flush();
}
catch (SocketException e)
{
if (!isConnected() || !socketIsConnected(_socket_))
{
throw new FTPConnectionClosedException("Connection unexpectedly closed.");
}
else
{
throw e;
}
}
if (_commandSupport_.getListenerCount() > 0)
_commandSupport_.fireCommandSent(command, message);
__getReply();
return _replyCode;
|
public void | setControlEncoding(java.lang.String encoding)Sets the character encoding used by the FTP control connection.
Some FTP servers require that commands be issued in a non-ASCII
encoding like UTF-8 so that filenames with multi-byte character
representations (e.g, Big 8) can be specified.
_controlEncoding = encoding;
|
public int | site(java.lang.String parameters)A convenience method to send the FTP SITE command to the server,
receive the reply, and return the reply code.
return sendCommand(FTPCommand.SITE, parameters);
|
public int | smnt(java.lang.String dir)A convenience method to send the FTP SMNT command to the server,
receive the reply, and return the reply code.
return sendCommand(FTPCommand.SMNT, dir);
|
private boolean | socketIsConnected(java.net.Socket socket)Checks if the socket is connected using reflection to be backward compatible.
The return value of this method is only meaningful in an java 1.4 environment.
if (socket == null)
{
return false;
}
try
{
Method isConnected = socket.getClass().getMethod("isConnected", null);
return ((Boolean) isConnected.invoke(socket, null)).booleanValue();
}
catch (NoSuchMethodException e)
{
return true;
}
catch (IllegalAccessException e)
{
return true;
}
catch (InvocationTargetException e)
{
return true;
}
|
public int | stat()A convenience method to send the FTP STAT command to the server,
receive the reply, and return the reply code.
return sendCommand(FTPCommand.STAT);
|
public int | stat(java.lang.String pathname)A convenience method to send the FTP STAT command to the server,
receive the reply, and return the reply code.
return sendCommand(FTPCommand.STAT, pathname);
|
public int | stor(java.lang.String pathname)A convenience method to send the FTP STOR command to the server,
receive the reply, and return the reply code. Remember, it is up
to you to manage the data connection. If you don't need this low
level of access, use {@link org.apache.commons.net.ftp.FTPClient}
, which will handle all low level details for you.
return sendCommand(FTPCommand.STOR, pathname);
|
public int | stou()A convenience method to send the FTP STOU command to the server,
receive the reply, and return the reply code. Remember, it is up
to you to manage the data connection. If you don't need this low
level of access, use {@link org.apache.commons.net.ftp.FTPClient}
, which will handle all low level details for you.
return sendCommand(FTPCommand.STOU);
|
public int | stou(java.lang.String pathname)A convenience method to send the FTP STOU command to the server,
receive the reply, and return the reply code. Remember, it is up
to you to manage the data connection. If you don't need this low
level of access, use {@link org.apache.commons.net.ftp.FTPClient}
, which will handle all low level details for you.
return sendCommand(FTPCommand.STOU, pathname);
|
public int | stru(int structure)A convenience method to send the FTP STRU command to the server,
receive the reply, and return the reply code.
return sendCommand(FTPCommand.STRU,
__modes.substring(structure, structure + 1));
|
public int | syst()A convenience method to send the FTP SYST command to the server,
receive the reply, and return the reply code.
return sendCommand(FTPCommand.SYST);
|
public int | type(int fileType, int formatOrByteSize)A convenience method to send the FTP TYPE command for text files
to the server, receive the reply, and return the reply code.
StringBuffer arg = new StringBuffer();
arg.append(__modes.charAt(fileType));
arg.append(' ");
if (fileType == LOCAL_FILE_TYPE)
arg.append(formatOrByteSize);
else
arg.append(__modes.charAt(formatOrByteSize));
return sendCommand(FTPCommand.TYPE, arg.toString());
|
public int | type(int fileType)A convenience method to send the FTP TYPE command to the server,
receive the reply, and return the reply code.
return sendCommand(FTPCommand.TYPE,
__modes.substring(fileType, fileType + 1));
|
public int | user(java.lang.String username)A convenience method to send the FTP USER command to the server,
receive the reply, and return the reply code.
return sendCommand(FTPCommand.USER, username);
|