/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* This class handles one client connection. It will interpret and act on the
* commands (like USER, GET, PUT etc...) sent through the socket passed to
* the constructor.
*
* To function it needs to be provided 2 handlers, one for the filesystem
* and one for authentication.
* @see FileSystemHandler
* @see AuthHandler
* @see #setHandlers(FtpFileSystemHandler,FtpAuthHandler)
*/
private boolean done = false;
private boolean logged = false;
private boolean epsvAll = false;
private boolean pasvEnabled = true;
private boolean portEnabled = true;
private boolean extendedEnabled = true;
private boolean binary = true;
private boolean useCrypto = false;
private boolean useDataCrypto = false;
{ "QUIT", "USER", "PASS", "CWD", "CDUP", "PWD", "TYPE", "NOOP", "RETR",
"PORT", "PASV", "EPSV", "EPRT", "SYST", "STOR", "STOU", "LIST", "NLST",
"RNFR", "RNTO", "DELE", "REST", "AUTH", "FEAT", "CCC", "PROT", "PBSZ"
};
private boolean isPasvSet() {
try {
} catch ( IOException e) {
}
}
return true;
return false;
}
if (isPasvSet()) {
if (useCrypto && useDataCrypto) {
ssl.setUseClientMode(false);
s = ssl;
}
return s.getOutputStream();
}
if (dataAddress != null) {
Socket s;
if (useCrypto) {
} else
dataAddress = null;
dataPort = 0;
return s.getOutputStream();
}
return null;
}
if (isPasvSet()) {
if (useCrypto && useDataCrypto) {
ssl.setUseClientMode(false);
s = ssl;
}
return s.getInputStream();
}
if (dataAddress != null) {
Socket s;
if (useCrypto) {
} else
dataAddress = null;
dataPort = 0;
return s.getInputStream();
}
return null;
}
if (epsvAll) {
return;
}
if (!portEnabled) {
return;
}
int i = 0, j = 4;
while (j > 0) {
if (i < 0)
break;
j--;
}
if (j != 0) {
return;
}
try {
dataPort = 0;
dataAddress = null;
}
}
if (epsvAll) {
return;
}
if (!extendedEnabled || !portEnabled) {
return;
}
if (!m.find()) {
return;
}
try {
} catch (UnknownHostException e) {
dataAddress = null;
return;
}
}
private void doPasv() {
if (!pasvEnabled) {
return;
}
try {
if (rAddress instanceof Inet6Address) {
return;
}
byte[] a = rAddress.getAddress();
} catch (IOException e) {
}
}
if (!extendedEnabled || !pasvEnabled) {
return;
}
epsvAll = true;
return;
}
try {
} catch (IOException e) {
}
}
try {
return;
}
if (binary) {
byte[] buf = new byte[2048];
int count;
if (restart > 0) {
restart = 0;
}
do {
if (count > 0)
} while (count >= 0);
}
}
} catch (IOException e) {
}
}
try {
return;
}
if (binary) {
byte[] buf = new byte[2048];
int count;
do {
if (count > 0)
} while (count >= 0);
}
}
} catch (IOException e) {
}
}
private void doList() {
try {
return;
}
byte[] buf = new byte[2048];
int count;
do {
if (count > 0)
} while (count >= 0);
}
} catch (IOException e) {
}
}
private boolean useTLS() {
}
return false;
return true;
}
private void stopTLS() {
if (useCrypto) {
try {
} catch (IOException e) {
// nada
}
try {
}
}
}
fsh = f;
auth = a;
}
parent = p;
}
public void terminate() {
done = true;
}
return ERROR;
if (blank < 0)
if (blank < 3)
return ERROR;
if (s.equalsIgnoreCase(commands[i]))
return i;
// Unknown command
return ERROR;
}
private boolean checkLogged() {
if (!logged) {
return false;
}
return true;
}
public void run() {
try {
// cmd.setSoTimeout(2000);
logged = true;
} catch (IOException e) {
e.printStackTrace();
return;
}
int res;
while (!done) {
try {
switch (res) {
case ERROR:
break;
case QUIT:
done = true;
break;
case USER:
logged = false;
else {
logged = true;
} else {
}
}
break;
case PASS:
break;
}
break;
}
logged = true;
break;
}
break;
case CWD:
if (checkLogged()) {
} else {
}
}
break;
case CDUP:
if (checkLogged()) {
else
}
break;
case PWD:
if (checkLogged()) {
}
break;
case NOOP:
if (checkLogged()) {
}
break;
case PORT:
if (checkLogged()) {
}
break;
case EPRT:
if (checkLogged()) {
}
break;
case PASV:
if (checkLogged())
doPasv();
break;
case EPSV:
if (checkLogged())
break;
case RETR:
if (checkLogged()) {
}
break;
case SYST:
if (checkLogged()) {
}
break;
case TYPE:
if (checkLogged()) {
continue;
}
binary = true;
else
binary = false;
}
break;
case STOR:
case STOU:
// TODO: separate STOR and STOU (Store Unique)
if (checkLogged()) {
}
break;
case LIST:
if (checkLogged()) {
doList();
}
break;
case NLST:
// TODO: implememt
break;
case DELE:
if (checkLogged()) {
break;
}
}
break;
case RNFR:
if (checkLogged()) {
if (renameFrom != null) {
break;
}
} else {
renameFrom = null;
}
}
break;
case RNTO:
if (checkLogged()) {
if (renameFrom == null) {
break;
}
} else {
}
renameFrom = null;
}
break;
case REST:
if (checkLogged()) {
if (restart > 0)
else
}
break;
case FEAT:
break;
case AUTH:
try {
ssl = (SSLSocket) sslFact.createSocket(cmd, cmd.getInetAddress().getHostName(), cmd.getPort(), false);
ssl.setUseClientMode(false);
} catch (IOException ioe) {
break;
}
useCrypto = true;
break;
}
break;
case CCC:
stopTLS();
break;
case PROT:
// PROT C : Clear protection level
// No protection on data channel;
useDataCrypto = false;
break;
}
// PROT P : Private protection level
// Data channel is integrity and confidentiality protected
useDataCrypto = true;
break;
}
break;
case PBSZ:
// TODO: finish
break;
}
} catch (InterruptedIOException ie) {
// loop
} catch (IOException e) {
e.printStackTrace();
return;
}
}
try {
} catch (IOException e) {
}
parent.removeClient(this);
}
}