Salut,
Je crée un client FTP en java.
Lors d'un transfert de fichiers d'un dossier Ftp vers un dossier spécifique de mon disque dur, java m'affiche un mesage d'erreur :
"java.io.FileNotFoundException: C:\Documents and Settings\Administrateur\Bureau\oo (Accès refusé)"
Pour le transfert, j'utilise la fonction :
ftp.getBinaryFile(...)
Voici mon script:
class FtpExample implements FtpObserver
{
private String name;
FtpBean ftp;
long num_of_bytes = 0;
private FtpListResult director;
public FtpExample()
{
// Create a new FtpBean object.
ftp = new FtpBean();
}
// Connect to a ftp server.
public void connect(String Log, String PW)
{
try
{
ftp.ftpConnect("10.50.3.51", Log, PW);
} catch(Exception e)
{
System.out.println(e);
}
}
// Close connection
public void close()
{
try
{
ftp.close();
} catch(Exception e)
{
System.out.println(e);
}
}
public Fichier mise_a_jour_tab()
{
Fichier tmp_fic= new Fichier();
FtpListResult ftplrs = null;
try
{
// Ouvre le dossier 'gg'dans lequel se trouve le fichier à importer'.
// Get its directory content.
ftp.setDirectory("gg/cc");
ftplrs = ftp.getDirectoryContent();
} catch(Exception e)
{
System.out.println(e);
}
// Print out the type and file name of each row.
while(ftplrs.next())
{
int type = ftplrs.getType();
if(type == FtpListResult.DIRECTORY)
System.out.print("DIR\t");
else if(type == FtpListResult.FILE)
System.out.print("FILE\t");
else if(type == FtpListResult.LINK)
System.out.print("LINK\t");
else if(type == FtpListResult.OTHERS)
System.out.print("OTHER\t");
System.out.println("Le fichier " + ftplrs.getName() + " à été enregistré sur votre disque");
getFile(ftplrs.getName());
tmp_fic.innit(ftplrs.getName());
}
return tmp_fic;
}
// Get the file.
public void getFile(String name)
{
try
{
ftp.getBinaryFile(name,"C:/Documents and Settings/Administrateur/Bureau/oo");
} 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)
{
}