neo1260
Messages postés32Date d'inscriptionvendredi 16 mai 2003StatutMembreDernière intervention 6 décembre 2004
-
6 avril 2004 à 13:34
neo1260
Messages postés32Date d'inscriptionvendredi 16 mai 2003StatutMembreDernière intervention 6 décembre 2004
-
8 avril 2004 à 12:08
Bonjour, je voudrais utiliser un jsp pour récupérer un fichier via le ftp sur une autre machine, j'utilise pour l'instant le client qui est proposé avec le ftpBean mais quand je le test j'ai toujours une erreur interne pas trés explicite:
description Le serveur a recontrer une erreur interne () qui l'a empèché de satisfaire la requête.
exception
javax.servlet.ServletException: ftp/FtpObserver
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:249).....
voici ma page jsp
<HTML>
<HEAD><TITLE>Test Java</TITLE></HEAD>
public class FtpConnect implements FtpObserver
{
FtpBean ftp;
long num_of_bytes = 0;
public FtpConnect()
{
// Create a new FtpBean object.
ftp = new FtpBean();
}
// Connect to a ftp server.
public void connect()
{
try
{
ftp.ftpConnect("127.0.0.1", "log", "pass");
} catch(Exception e)
{
System.out.println(e);
}
}
// Close connection
public void close()
{
try
{
ftp.close();
} catch(Exception e)
{
System.out.println(e);
}
}
// Go to directory.
public void listDirectory()
{
FtpListResult ftplrs = null;
try
{
// Go to directory 'c:/'.
ftp.setDirectory("c:/");
// Get its directory content.
ftplrs = ftp.getDirectoryContent();
} catch(Exception e)
{
System.out.println(e);
}
}
// Get the file.
public void getFile()
{
try
{
// Get the file 'test.txt' and save it to
// the name 'local_file_name' in the hard disk.
ftp.getBinaryFile("test.txt", "C:/tomcat/webapps/test", this);
} catch(Exception e)
{
System.out.println(e);
}
}
// Implemented for FtpObserver interface.
// To monitor download progress.
public void byteRead(int bytes)
{
num_of_bytes += bytes;
System.out.println(num_of_bytes + " of bytes read already.");
}
// Needed to implements by FtpObserver interface.
public void byteWrite(int bytes)
{
}
// Main
public static void main(String arg[])
{
FtpConnect example = new FtpConnect();
example.connect();
example.listDirectory();
example.getFile();
example.close();
}
}
pour l'instant je travail en local, j'utilise un serveur tomcat et un serveur filezilla pour le ftp.
Si quelqu'un voit la solution sa serais cool, merci d'avance pour votre aide.
neo1260
Messages postés32Date d'inscriptionvendredi 16 mai 2003StatutMembreDernière intervention 6 décembre 2004 7 avril 2004 à 11:40
Bonjour, mon programme de client ftp fonctionne, maintenant j'ai un autre probléme, j'ai créer un jsp qui fonctionne bien, qui ouvre un fichier text et affiche dans la page web, le text. Le probléme est que j'essai de rajouté dans mon java, le programme FTP afin de récupérer se fichier text sur une autre machine et a chaque fois ke je lance mon jsp j'ai une erreur interne:
description Le serveur a recontrer une erreur interne () qui l'a empèché de satisfaire la requête.
private static String txt;
FtpBean ftp;
long num_of_bytes = 0;
public Test() {
// Create a new FtpBean object.
ftp = new FtpBean();
this.txt = " ";
}
// Connect to a ftp server.
public void connect()
{
try
{
ftp.ftpConnect("127.0.0.1", "seb", "seb");
} catch(Exception e)
{
System.out.println(e);
}
}
// Close connection
public void close()
{
try
{
ftp.close();
} catch(Exception e)
{
System.out.println(e);
}
}
// Go to directory.
public void listDirectory()
{
FtpListResult ftplrs = null;
try
{
// Go to directory '/test'.
ftp.setDirectory("/");
// Get its directory content.
ftplrs = ftp.getDirectoryContent();
} catch(Exception e)
{
System.out.println(e);
}
}
// Get the file.
public void getFile()
{
try
{
// Get the file 'test.txt' and save it to
// the name 'local_file_name' in the hard disk.
ftp.getAsciiFile ("test.txt", "test1.txt","\r", this);
} catch(Exception e)
{
System.out.println(e);
}
}
// Implemented for FtpObserver interface.
// To monitor download progress.
public void byteRead(int bytes)
{
num_of_bytes += bytes;
System.out.println(num_of_bytes + " of bytes read already.");
}
// Needed to implements by FtpObserver interface.
public void byteWrite(int bytes)
{
}
//get the file via FTP
public void getFtp() {
Test connect = new Test();
connect.connect();
connect.listDirectory();
connect.getFile();
connect.close();
}
//read the file
public void setText() {
try {
FileReader text = new FileReader("c://test.txt");
int caractere;
do {
caractere = text.read();
if (caractere != -1){
txt += (char)caractere;
}
}while (caractere != -1);
} catch (FileNotFoundException e) {
System.out.println("Exception fichier non trouvé : " + e.getMessage());
} catch (IOException e) {
System.out.println("Exception entrée/sortie : " + e.getMessage());
}
}
//print the file in the JSP page
public String getText ()
{
return (this.txt);
}
}