Tema: FTP con JAVA
Ver Mensaje Individual
  #6 (permalink)  
Antiguo 17/09/2008, 08:43
gdapice
 
Fecha de Ingreso: septiembre-2008
Mensajes: 4
Antigüedad: 16 años, 5 meses
Puntos: 0
Respuesta: FTP con JAVA

tendrian los metodos o alguna ayuda para darme, tengo que hacer un metodo para subir un archivo a un servidor, utilizo jsf y el api de java pero no puedo hacer que funcione les muestro lo que tengo

Código:
 public boolean connect(String host, int port)
        throws UnknownHostException, IOException
    {
        connectionSocket = new Socket(host, port);
        outputStream = new PrintStream(connectionSocket.getOutputStream());
        inputStream = new BufferedReader(new
                       InputStreamReader(connectionSocket.getInputStream()));

        if (!isPositiveCompleteResponse(getServerReply())){
            disconnect();
            return false;
        }

        return true;
    }

public boolean login(String username, String password)
        throws IOException
    {
        int response = executeCommand("user " + username);
        if (!isPositiveIntermediateResponse(response)) return false;
        response = executeCommand("pass " + password);
        loggedIn = isPositiveCompleteResponse(response);
        return loggedIn;
    }

public boolean uploadFile(String fileName)
        throws IOException
    {
        return writeDataFromFile("put " + fileName, fileName);
    }

public boolean writeDataFromFile(String command, String fileName)
        throws IOException
    {
        // Open the local file
        RandomAccessFile infile = new RandomAccessFile(fileName, "r");

        // Do restart if desired
        if (restartPoint != 0) {
            debugPrint("Seeking to " + restartPoint);
            infile.seek(restartPoint);
        }

        // Convert the RandomAccessFile to an InputStream
        FileInputStream fileStream = new FileInputStream(infile.getFD());
        boolean success = executeDataCommand(command, fileStream);

        infile.close();

        return success;
    }

public boolean executeDataCommand(String command, InputStream in)
        throws IOException
    {
        // Open a data socket on this computer
        ServerSocket serverSocket = new ServerSocket(0);
        if (!setupDataPort(command, serverSocket)) return false;
        Socket clientSocket = serverSocket.accept();

        // Transfer the data
        OutputStream out = clientSocket.getOutputStream();
        transferData(in, out);

        // Clean up the data structures
        out.close();
        clientSocket.close();
        serverSocket.close();

        return isPositiveCompleteResponse(getServerReply());    
    }

private boolean isPositiveCompleteResponse(int response)
    {
        return (response >= 200 && response < 300);
    }

son varios metodos me lo pasaron yo lo modifique un toque pero no lo puedo hacer funcionar