Ver Mensaje Individual
  #2 (permalink)  
Antiguo 09/11/2010, 17:09
pritok
 
Fecha de Ingreso: octubre-2010
Ubicación: Asturias
Mensajes: 14
Antigüedad: 13 años, 6 meses
Puntos: 0
Respuesta: Subir imagen por ftp

Tifany, no se lo que haces mal, porque no me he parado mucho a leer tu codigo. Tengo un codigo que sube una imagen al FTP y lo hace bien, sin errores, quiza te pueda ayudar. Yo uso ImageIO, en lugar de escribir directamente sobre el os.

Bueno eso, que espero que te sirva.

Saludos.


import java.io.IOException;
import java.io.OutputStream;
import java.net.URL;
import java.net.URLConnection;
import java.awt.image.BufferedImage;

import javax.imageio.ImageIO;

public class FTPImageUploader {
private static String user = "my_user";
private static String pass = "my_pass";
private static String host = "my_host";
private BufferedImage image;
private String filename;

public FTPImageUploader(BufferedImage image, String filename) {
this.image = image;
this.filename = filename;
this.run();
}

public void run () {
try {
URL url = new URL("ftp://"+user+":"+pass+"@"+host+filename+";type=i");
URLConnection connection = url.openConnection();
OutputStream os = connection.getOutputStream();;
ImageIO.write(this.image, "JPEG", os);
} catch (IOException e) {
e.printStackTrace();
System.out.println(this.filename);
}
}

}