//mode
if(ftpCmd.equalsIgnoreCase("mode")){
//case "mode": {
try {
String arg = ftpCmdtok.nextToken();
if (arg.equals("s"))
showMessage("200 MODE S.");
else
showMessage("501 MODE S not found.");
}
catch (Exception e) {
showMessage("500 MODE Syntax.");
}
return;
}
//stru
if(ftpCmd.equalsIgnoreCase("stru")){
// case "stru": {
try {
String arg = ftpCmdtok.nextToken();
if (arg.equals("f"))
showMessage("200 STRU F.");
else
showMessage("501 STRU F not found.");
}
catch (Exception e) {
showMessage("500 STRU Syntax.");
}
return;
} //list
if(ftpCmd.equalsIgnoreCase("list")) {
//case "list": {
String arg;
if (ftpCmdtok.hasMoreTokens())
arg = ftpCmdtok.nextToken();
else
arg = "."; ftpList(arg);
return;
}
//nlst;
if(ftpCmd.equalsIgnoreCase("nlst")) {
//case "nlst": {
String arg;
if (ftpCmdtok.hasMoreTokens())
arg = ftpCmdtok.nextToken();
else
arg = "."; ftpList(arg);
return;
}
// else if(ftpCmd=="cdup")
if(ftpCmd.equalsIgnoreCase("cdup")){
changeDirectory(currentPath.substring(0,
currentPath.lastIndexOf("\\")));
return;
}
if(ftpCmd.equalsIgnoreCase("cwd")) {
//case "cwd":{
try{
String arg= ftpCmdtok.nextToken();
if(arg.equals("..")) {
changeDirectory(currentPath.substring(0,
currentPath.lastIndexOf("\\")));
}
else changeDirectory(arg);
}
catch(Exception e){
showMessage("500 CWD syntax.");
}
return;
}
//xpwd: current directory;
if(ftpCmd.equalsIgnoreCase("xpwd")){
//case "xpwd":
showMessage("200 PWD "+currentPath);
return;
}
//stor :put
if (ftpCmd.equalsIgnoreCase("stor")) {
//case "stor":{
try{
String arg=ftpCmdtok.nextToken();
String path=currentPath+"\\"+arg;
//if (!(path.getCanonicalPath().startsWith(
// rootPath.getCanonicalPath())))
if(!path.startsWith(rootPath))
throw new SecurityException(); if(blnBinary) putLocalBinaryFile(path,arg);
else putLocalASCIIFile(path,arg);
}
catch(Exception ex) {
showMessage("500 STOR syntax.");
}
return;
} //retr: get
if(ftpCmd.equalsIgnoreCase("retr")) {
//case "retr":{
try{
String arg=ftpCmdtok.nextToken();
File path=new File(currentPath,arg); if(!path.getCanonicalPath().startsWith(
rootPath.getCanonicalPath()))
throw new SecurityException();
getRemoteFile(path,arg);
}
catch(Exception ex) {
showMessage("500 RETR syntax.");
}
return;
}
//help:
if(ftpCmd.equalsIgnoreCase("help")) {
//case "help":{
String strhelp=
"Java FTP Server - <version 1.0> - ready."+linesep+"Help Message.";
showMessage("200 Remotehelp "+strhelp);
return;
}
//noop;
if(ftpCmd.equalsIgnoreCase("noop")){
showMessage("200 OK.");
return ;
}
//quit
if(ftpCmd.equalsIgnoreCase("quit")) {
//case "quit":{
showMessage(
"221 Service closing control connection .Goodbye.");
resetDefault();
return;
}
showMessage("502 "+ftpCmd+" not found");
}
catch(Exception e){
showMessage("500 "+ftpCmd+" Syntax.");
}
}
if(ftpCmd.equalsIgnoreCase("mode")){
//case "mode": {
try {
String arg = ftpCmdtok.nextToken();
if (arg.equals("s"))
showMessage("200 MODE S.");
else
showMessage("501 MODE S not found.");
}
catch (Exception e) {
showMessage("500 MODE Syntax.");
}
return;
}
//stru
if(ftpCmd.equalsIgnoreCase("stru")){
// case "stru": {
try {
String arg = ftpCmdtok.nextToken();
if (arg.equals("f"))
showMessage("200 STRU F.");
else
showMessage("501 STRU F not found.");
}
catch (Exception e) {
showMessage("500 STRU Syntax.");
}
return;
} //list
if(ftpCmd.equalsIgnoreCase("list")) {
//case "list": {
String arg;
if (ftpCmdtok.hasMoreTokens())
arg = ftpCmdtok.nextToken();
else
arg = "."; ftpList(arg);
return;
}
//nlst;
if(ftpCmd.equalsIgnoreCase("nlst")) {
//case "nlst": {
String arg;
if (ftpCmdtok.hasMoreTokens())
arg = ftpCmdtok.nextToken();
else
arg = "."; ftpList(arg);
return;
}
// else if(ftpCmd=="cdup")
if(ftpCmd.equalsIgnoreCase("cdup")){
changeDirectory(currentPath.substring(0,
currentPath.lastIndexOf("\\")));
return;
}
if(ftpCmd.equalsIgnoreCase("cwd")) {
//case "cwd":{
try{
String arg= ftpCmdtok.nextToken();
if(arg.equals("..")) {
changeDirectory(currentPath.substring(0,
currentPath.lastIndexOf("\\")));
}
else changeDirectory(arg);
}
catch(Exception e){
showMessage("500 CWD syntax.");
}
return;
}
//xpwd: current directory;
if(ftpCmd.equalsIgnoreCase("xpwd")){
//case "xpwd":
showMessage("200 PWD "+currentPath);
return;
}
//stor :put
if (ftpCmd.equalsIgnoreCase("stor")) {
//case "stor":{
try{
String arg=ftpCmdtok.nextToken();
String path=currentPath+"\\"+arg;
//if (!(path.getCanonicalPath().startsWith(
// rootPath.getCanonicalPath())))
if(!path.startsWith(rootPath))
throw new SecurityException(); if(blnBinary) putLocalBinaryFile(path,arg);
else putLocalASCIIFile(path,arg);
}
catch(Exception ex) {
showMessage("500 STOR syntax.");
}
return;
} //retr: get
if(ftpCmd.equalsIgnoreCase("retr")) {
//case "retr":{
try{
String arg=ftpCmdtok.nextToken();
File path=new File(currentPath,arg); if(!path.getCanonicalPath().startsWith(
rootPath.getCanonicalPath()))
throw new SecurityException();
getRemoteFile(path,arg);
}
catch(Exception ex) {
showMessage("500 RETR syntax.");
}
return;
}
//help:
if(ftpCmd.equalsIgnoreCase("help")) {
//case "help":{
String strhelp=
"Java FTP Server - <version 1.0> - ready."+linesep+"Help Message.";
showMessage("200 Remotehelp "+strhelp);
return;
}
//noop;
if(ftpCmd.equalsIgnoreCase("noop")){
showMessage("200 OK.");
return ;
}
//quit
if(ftpCmd.equalsIgnoreCase("quit")) {
//case "quit":{
showMessage(
"221 Service closing control connection .Goodbye.");
resetDefault();
return;
}
showMessage("502 "+ftpCmd+" not found");
}
catch(Exception e){
showMessage("500 "+ftpCmd+" Syntax.");
}
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货