Ver Mensaje Individual
  #2 (permalink)  
Antiguo 12/04/2016, 15:59
Avatar de Arkhan6
Arkhan6
 
Fecha de Ingreso: agosto-2010
Mensajes: 23
Antigüedad: 13 años, 9 meses
Puntos: 0
Respuesta: Abrir documento PDF con FTP en un servidor remoto

Muy buenas, mas o menos es ésta mi idea, lo único que para poder abrir el archivo PDF primero tengo que copiarlo en mi ordenador y despues abrirlo.

Lo que quiero es abrirlo desde el servidor remoto sin tener que copiarlo en mi ordenador.

¿Podrian darme alguna idea para poder continuar buscando información? Muchas gracias.

Código Java:
Ver original
  1. import java.awt.Desktop;
  2. import java.io.File;
  3. import java.io.IOException;
  4. import java.io.FileOutputStream;
  5. import java.io.InputStream;
  6. import java.io.OutputStream;
  7.  
  8. import org.apache.commons.net.ftp.FTPClient;
  9.  
  10. public class FTPConnect {
  11.     private final String server = "";
  12.     private final int port ="";
  13.     private final String user = "";
  14.     private final String pass = "";
  15.    
  16.     public FTPConnect(){
  17.        
  18.     }  
  19.    
  20.     public void openFile(String name_doc, String directory){
  21.          FTPClient client = new FTPClient();
  22.        
  23.         try {
  24.             client.connect(server, port);
  25.             client.login(user, pass);
  26.             client.changeWorkingDirectory("/directorioPrincipal/"+directory+"/");
  27.            
  28.             /*if (success) {
  29.                 System.out.println("Directorio cambiado correctamente.");
  30.             } else {
  31.                 System.out.println("Error al cambiar el directorio.");
  32.             }*/
  33.             File file = new File(name_doc);
  34.             InputStream inputStream = client.retrieveFileStream(name_doc);
  35.            
  36.              // Copy file
  37.                 OutputStream outputStream = new FileOutputStream(file);
  38.                 byte[] buffer = new byte[1024];
  39.                 int length;
  40.                 while ((length = inputStream.read(buffer)) > 0) {
  41.                     outputStream.write(buffer, 0, length);
  42.                 }
  43.                 outputStream.close();
  44.                 inputStream.close();
  45.            
  46.             // Open file
  47.             Desktop.getDesktop().open(file);
  48.                        
  49.             client.logout();
  50.         } catch (IOException e) {
  51.             e.printStackTrace();
  52.         } finally {
  53.             try {              
  54.                 client.disconnect();
  55.             } catch (IOException e) {
  56.                 e.printStackTrace();
  57.             }
  58.         }
  59.     }
  60. }