Expertos En Ftp Informatica , Problema Con Ifs

Hola , tengo todas las clases echas las tres y lo ejecuto pero debe ser q la clase clienteftp y la classe servidorftp se llevan muy mal te paso la gramatica de la clase servidorftp y me comentas lo q te parece toy casi seguro q es el funcionamiento de los ifs q tengo uestos porqe si no se q sera.

Aqui os dejo la gramatica del servidor


import java.io.*;
import java.net.*;
import java.util.*;
import java.text.DateFormat;

class ServidorFTP {
public static void main(String[] args) {
LinkedList listaUploads = new LinkedList();
char seleccion;
byte[] ArrayB;

try {
ServerSocket Sserv = new ServerSocket(9999);
DatagramSocket Sdat = new DatagramSocket(8889);
while (true) {
Socket ClienteS = Sserv.accept();
System.out.println("-cliente conectado-");
System.out.println("");
PrintWriter bye = new PrintWriter(ClienteS.getOutputStream(), true);
BufferedReader hi = new BufferedReader(new InputStreamReader(ClienteS.getInputStream()));

do {
String mens;
DatagramPacket dp;
Calendar calendario = Calendar.getInstance();
Date dma = calendario.getTime();
DateFormat formatear = DateFormat.getDateInstance(DateFormat.FULL);

seleccion =hi.readLine().charAt(0);

if (seleccion == 0) {

ClienteS.close();
System.out.println("-cliente desconectado-");

//Enviamos la fechal al LOG
mens = "desconexio@" + formatear.format(dma) + "@";
ArrayB = mens.getBytes();

//Enviamos el paquete
dp = new DatagramPacket(ArrayB, ArrayB.length,
InetAddress.getLocalHost(), 8888);
try {
Sdat.send(dp);
}
catch (IOException e) {
System.err.println("error en el envio");
}
}
else{
if (seleccion == 1) {

//Mostramos la lista de ficheros subidos
ListIterator iteLis = listaUploads.listIterator(0);
System.out.println("uploads: ");
while (iteLis.hasNext()) {
System.out.println("---> " + (String) iteLis.next());
}
if (listaUploads.isEmpty()) {
System.out.println("no hay ningun upload");
}
System.out.println("");

//Mandamos mensaje al LOG
mens = "lista uploads@" + formatear.format(dma) + "@";
ArrayB = mens.getBytes();

//Enviamos el paquete
dp = new DatagramPacket(ArrayB, ArrayB.length,
InetAddress.getLocalHost(), 8888);
try {
Sdat.send(dp);
}
catch (IOException e) {
System.err.println("error en el envio");
}
}
else{
if (seleccion == 2) {
//Pedimos el nombre del fichero a subir
String nombreUploadBi = "";
nombreUploadBi = hi.readLine();

//Recibimos el tamaño del archivo
long tamañobi = 0;
tamañobi = Long.parseLong(hi.readLine());

//Recibimos y escribimos cada byte que nos mandan
FileOutputStream fileOutS = new FileOutputStream(nombreUploadBi);
DataInputStream gate = new DataInputStream(ClienteS.getInputStream());

for (int i = 0; i < tamañobi; i++) {
fileOutS.write(hi.read());
}
fileOutS.close();

//Añadimos el nombre del fichero que nos caban de pasar a la lista
listaUploads.addLast(nombreUploadBi);

//Mandamos mensaje al LOG
mens = "upload fichero binario@" + formatear.format(dma) + "@";
ArrayB = mens.getBytes();

//Enviamos el paquete
dp = new DatagramPacket(ArrayB, ArrayB.length,
InetAddress.getLocalHost(), 8888);
try {
Sdat.send(dp);
}
catch (IOException e) {
System.err.println("error en el envio");
}

}
else{
if (seleccion == 3) {
//Pedimos el nombre del fichero a subir
String nombreUploadText = "";
nombreUploadText = hi.readLine();

//Creamos un archivo con ese nombre y lo escribimos
BufferedWriter buffw = new BufferedWriter(new FileWriter(
nombreUploadText));
String texto;
texto = hi.readLine();
while (!texto.equals("__FIN__")) {
buffw.write(texto + "\r" + "\n");
texto = hi.readLine();
}
buffw.close();

//Añadimos el nombre del fichero que nos caban de pasar a la lista
listaUploads.addLast(nombreUploadText);

//Mandamos mensaje al LOG
mens = "upload fichero texto@" + formatear.format(dma) + "@";
ArrayB = mens.getBytes();

//Enviamos el paquete
dp = new DatagramPacket(ArrayB, ArrayB.length,
InetAddress.getLocalHost(), 8888);
try {
Sdat.send(dp);
}
catch (IOException e) {
System.err.println("error en el envio");
}

}
else{
if(seleccion==4)
{
String downloadfichbi = "";
downloadfichbi = hi.readLine();

//Contamos los bytes del fichero
long tamañobi2 = 0;
File fich = new File(downloadfichbi);
FileInputStream fichInS = new FileInputStream(fich);
tamañobi2 = (int)fich.length();

//Enviamos el tamaño de archivo
bye.println(tamañobi2);

//Leemos y enviamos el archivo al cliente
DataOutputStream exit = new DataOutputStream(ClienteS.getOutputStream());

for (long i=0; i exit.write(fichInS.read());
}
fichInS.close();

//Mandamos mensaje al LOG
mens = "download fichero binario@" + formatear.format(dma) + "@";
ArrayB = mens.getBytes();

//Enviamos el paquete
dp = new DatagramPacket(ArrayB, ArrayB.length, InetAddress.getLocalHost(), 8888);
try {
Sdat.send(dp);
}
catch (IOException e) {
System.err.println("error en el envio");
}

}
else{
if(seleccion==5)
{
//Pedimos el nombre del fichero a bajar
String nombreDownloadText = "";
nombreDownloadText = hi.readLine();

//Leemos el texto del fichero y lo enviamos
BufferedReader buffr = new BufferedReader(new FileReader(nombreDownloadText));
while (buffr.ready()) {
bye.println(buffr.readLine());
}
buffr.close();

//Para comunicarle al cliente que ya ha acabado el archivo le enviamos una clave
bye.println("<__FIN__");

//Mandamos mensaje al LOG
mens = "download fichero texto@" + formatear.format(dma) + "@";
ArrayB = mens.getBytes();

//Enviamos el paquete
dp = new DatagramPacket(ArrayB, ArrayB.length, InetAddress.getLocalHost(), 8888);
try {
Sdat.send(dp);
}
catch (IOException e) {
System.err.println("error en el envio");
}

}
else{
if(seleccion==6){
//Pedimos el nombre del fichero que queremos borrar
String eraseFich = "";
eraseFich = hi.readLine();

//Borramos el fichero
File erasefich = new File(eraseFich);
erasefich.delete();

//Mandamos mensaje al LOG
mens = "borrar fichero@" + formatear.format(dma) + "@";
ArrayB = mens.getBytes();

//Enviamos el paquete
dp = new DatagramPacket(ArrayB, ArrayB.length, InetAddress.getLocalHost(), 8888);
try {
Sdat.send(dp);
}
catch (IOException e) {
System.err.println("error en el envio");
}
}
}
}
}
}
}
}
} while (seleccion != 'a');
}
}
catch (IOException e) {
System.out.println("ERROR EN EL SERVIDOR");
}
}
}





Alquien me podria decir donde esta el problema ?


Saludos y gracias de antemano
0 respuestas