File download FTP server

0

some recommendation? my client receives the "file" but does not do any method to accept it, my client just sends the command to make it run on the server.

this is my download method in my class commands

    public void download (String filename){
        File f = new File(path + filename);

        System.out.println("");
        System.out.println("Starting");
        System.out.println(">>Sending File : "+ filename + "  " );
        System.out.println(">>Please wait...");
        try{if(f.exists()){
          FileInputStream fis = new FileInputStream(Server.s.getInputStream() + path + filename); //linea 87
          BufferedOutputStream bout = new BufferedOutputStream(Server.s.getOutputStream());
          BufferedInputStream bis = new BufferedInputStream(fis);
               while(true){
               byte[] buffer = new byte[1024] ;
               int i = bis.read(buffer, 0, buffer.length);
               if (i == - 1) {
                   break;
               }
               bout.write(buffer, 0, i);
               bout.flush();
               }
   }

this is the error that gives me to execute it

java.io.FileNotFoundException: 
java.net.SocketInputStream@521e4820
C:\Users\Eduardo\Desktop\Eduardo\Uru\Clases Programacion\POO\CLI\cesar.txt 
(El nombre de archivo, el nombre de directorio o la sintaxis de la etiqueta del volumen no son correctos)
at java.io.FileInputStream.open0(Native Method)
at java.io.FileInputStream.open(FileInputStream.java:195)
at java.io.FileInputStream.<init>(FileInputStream.java:138)
at java.io.FileInputStream.<init>(FileInputStream.java:93)
at eagz.org.Commands.download(Commands.java:87)
at eagz.org.Menu.menu(Menu.java:52)
at eagz.org.ConexionServer.run(ConexionServer.java:15)

This is my client class

package eagz.org;

import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.net.Socket;
import java.util.Scanner;

public class Cliente {
static int PORT = 9000;
static String IP = "localhost";
static Scanner input = new Scanner (System.in);

public static void main(String[] args){ 
    try {
        while(true){
        Socket s = new Socket(IP, PORT);
        ObjectOutputStream oos = new ObjectOutputStream(s.getOutputStream());
        ObjectInputStream ois = new ObjectInputStream(s.getInputStream());
        System.out.println(" ");
        System.out.println("-- Client Side --");
        System.out.println("Connecting to Server -> " +  IP  + "/" + PORT);
        System.out.println("Designated Commands: "+"->Create "+"->Read" + "->Rename "+"->Delete "+"->Download "+"->Upload");
        System.out.println("C:>");
        String commandmsg = input.nextLine();
        oos.writeObject(commandmsg);
        Object servermsg = ois.readObject();
        System.out.println("From Server :"+ servermsg);
        oos.close();
        ois.close();
        }   
    }catch(Exception e){
        e.printStackTrace();            
    }
}

}

    
asked by Eduardo Gonzalez 19.04.2017 в 19:29
source

1 answer

0

Look carefully at the URL of you want to read the data:

"java.net.SocketInputStream@521e4820 C: \ Users \ Eduardo \ Desktop \ Eduardo \ Uru \ Classes Programming \ POO \ CLI \ cesar.txt "

I'm not surprised that this route can not exist. Your wrong code is:

FileInputStream fis = new FileInputStream(Server.s.getInputStream() + path + filename);

I'm not sure if you want to build the FileInputStream of Server.s.getInputStream() , but I'm sure it will not work with both at the same time. So dependent on what you want as a source path you can use:

FileInputStream fis = new FileInputStream(Server.s.getInputStream());

or

FileInputStream fis = new FileInputStream(path + filename);

or in this case even simpler:

FileInputStream fis = new FileInputStream(f);

as you already tried if this route exists.

    
answered by 19.04.2017 в 23:58