IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Entrée/Sortie Java Discussion :

Problème téléchargement FTP


Sujet :

Entrée/Sortie Java

  1. #1
    Membre à l'essai
    Homme Profil pro
    Développeur .NET
    Inscrit en
    Mai 2010
    Messages
    17
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Nord (Nord Pas de Calais)

    Informations professionnelles :
    Activité : Développeur .NET

    Informations forums :
    Inscription : Mai 2010
    Messages : 17
    Points : 16
    Points
    16
    Par défaut Problème téléchargement FTP
    Bonjour,
    je souhaite récupérer un fichier sur un FTP, mais j'ai une erreur sur la fonction download ("permission require")
    je n'arrive pas a la résoudre vu que en passant par Firefox je récupère le fichier sans problème.
    Peut être je m'y prends mal, donc est-ce la bonne méthode ?

    Ou connaissez-vous un serveur FTP (autre que e-nautia) pour y stocker des fichiers et les récupérer par un programme java ?
    j'utilise la librairie ftp4j-1.6.1.jar
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    FTPClient client = new FTPClient(); 
    try {
       client.connect("e-nautia.com");
       client.login("login", "mdp");
       client.setType(FTPClient.TYPE_BINARY);
       client.download("e-nautia.com/maj.xml", new java.io.File("\\Chemin du dossier\\maj.xml"));
       client.logout();
    }
    catch (Exception e)
    {
       e.printStackTrace();
    }
    merci d'avance
    Bonne journée

    edit:
    petite précision concernant le message de retour:
    (je ne sais pas si sa peut aider)

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
     
    java.net.SocketException: Permission denied: recv failed
    	at java.net.SocketInputStream.socketRead0(Native Method)
    	at java.net.SocketInputStream.read(SocketInputStream.java:150)
    	at java.net.SocketInputStream.read(SocketInputStream.java:121)
    	at sun.nio.cs.StreamDecoder.readBytes(StreamDecoder.java:283)
    	at sun.nio.cs.StreamDecoder.implRead(StreamDecoder.java:325)
    	at sun.nio.cs.StreamDecoder.read(StreamDecoder.java:177)
    	at sun.nio.cs.StreamDecoder.read0(StreamDecoder.java:126)
    	at sun.nio.cs.StreamDecoder.read(StreamDecoder.java:112)
    	at java.io.InputStreamReader.read(InputStreamReader.java:168)
    	at it.sauronsoftware.ftp4j.NVTASCIIReader.readLine(NVTASCIIReader.java:105)
    	at it.sauronsoftware.ftp4j.FTPCommunicationChannel.read(FTPCommunicationChannel.java:142)
    	at it.sauronsoftware.ftp4j.FTPCommunicationChannel.readFTPReply(FTPCommunicationChannel.java:187)
    	at it.sauronsoftware.ftp4j.FTPClient.openPassiveDataTransferChannel(FTPClient.java:3534)
    	at it.sauronsoftware.ftp4j.FTPClient.openDataTransferChannel(FTPClient.java:3468)
    	at it.sauronsoftware.ftp4j.FTPClient.download(FTPClient.java:3297)
    	at it.sauronsoftware.ftp4j.FTPClient.download(FTPClient.java:3208)
    	at it.sauronsoftware.ftp4j.FTPClient.download(FTPClient.java:3073)
    	at ftp.RecupVersion.recup(RecupVersion.java:27)
    	at Main.main(Main.java:29)

  2. #2
    Membre éclairé Avatar de JoeChip
    Profil pro
    Inscrit en
    Septembre 2008
    Messages
    536
    Détails du profil
    Informations personnelles :
    Localisation : Belgique

    Informations forums :
    Inscription : Septembre 2008
    Messages : 536
    Points : 803
    Points
    803
    Par défaut
    Je ne connais pas cette librairie (j'utilise apache.commons.net), mais je regarderais le log côté serveur ftp, pour avoir des détails.

  3. #3
    Membre à l'essai
    Homme Profil pro
    Développeur .NET
    Inscrit en
    Mai 2010
    Messages
    17
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Nord (Nord Pas de Calais)

    Informations professionnelles :
    Activité : Développeur .NET

    Informations forums :
    Inscription : Mai 2010
    Messages : 17
    Points : 16
    Points
    16
    Par défaut
    Après recherche, je me suis rabattu sur java org.apache.commons.net.ftp mais j'ai encore une erreur sur ftp.listFiles();
    S'auriez vous m'aider?
    merci d'avance

    voici le code:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
     
    try
    		{
    			String server = "e-nautia.com";
    			String username = "login";
    			String password = "password";
    			String folder = "/";
    			String destinationFolder = ".\\";
     
    			// Connect and logon to FTP Server
     
    			FTPClient ftp = new FTPClient();
    			ftp.connect( server );
    			ftp.login( username, password );
    			System.out.println("Connected to " + server + ".");
    			System.out.print(ftp.getReplyString());
     
    			// List the files in the directory
     
    			ftp.changeWorkingDirectory( folder );
    			FTPFile[] files = ftp.listFiles();
    			System.out.println( "Number of files in dir: " + files.length );
    			DateFormat df = DateFormat.getDateInstance( DateFormat.SHORT );
    			for( int i=0; i<files.length; i++ )
    			{
     
    				//Date fileDate = files[ i ].getTimestamp().getTime();
    				//if( fileDate.compareTo( start.getTime() ) >= 0 &&
    				// fileDate.compareTo( end.getTime() ) <= 0 )
    				//{
    				// Download a file from the FTP Server
     
    				System.out.print( df.format( files[ i ].getTimestamp().getTime() ) );
    				System.out.println( "\t" + files[ i ].getName() );
    				File file = new File( destinationFolder + File.separator + files[ i ].getName() );
    				FileOutputStream fos = new FileOutputStream( file );
    				ftp.retrieveFile( files[ i ].getName(), fos );
    				fos.close();
     
    				//file.setLastModified( fileDate.getTime() );
    			}
     
    			//}
     
    			// Logout from the FTP Server and disconnect
     
    			ftp.logout();
    			ftp.disconnect();
     
    		}
    		catch( Exception e )
    		{
    			e.printStackTrace();
    		}
    et voici l'erreur:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
     
    java.net.SocketException: Software caused connection abort: socket write error
    	at java.net.SocketOutputStream.socketWrite0(Native Method)
    	at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:109)
    	at java.net.SocketOutputStream.write(SocketOutputStream.java:153)
    	at sun.nio.cs.StreamEncoder.writeBytes(StreamEncoder.java:221)
    	at sun.nio.cs.StreamEncoder.implFlushBuffer(StreamEncoder.java:291)
    	at sun.nio.cs.StreamEncoder.implFlush(StreamEncoder.java:295)
    	at sun.nio.cs.StreamEncoder.flush(StreamEncoder.java:141)
    	at java.io.OutputStreamWriter.flush(OutputStreamWriter.java:229)
    	at java.io.BufferedWriter.flush(BufferedWriter.java:254)
    	at org.apache.commons.net.ftp.FTP.__send(FTP.java:496)
    	at org.apache.commons.net.ftp.FTP.sendCommand(FTP.java:470)
    	at org.apache.commons.net.ftp.FTP.sendCommand(FTP.java:547)
    	at org.apache.commons.net.ftp.FTP.port(FTP.java:872)
    	at org.apache.commons.net.ftp.FTPClient._openDataConnection_(FTPClient.java:667)
    	at org.apache.commons.net.ftp.FTPClient.initiateListParsing(FTPClient.java:2990)
    	at org.apache.commons.net.ftp.FTPClient.initiateListParsing(FTPClient.java:2965)
    	at org.apache.commons.net.ftp.FTPClient.listFiles(FTPClient.java:2623)
    	at org.apache.commons.net.ftp.FTPClient.listFiles(FTPClient.java:2670)
    	at ManipFichier.getDataFiles.main(getDataFiles.java:37)

  4. #4
    Membre du Club Avatar de dark.jabberwock
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Décembre 2009
    Messages
    38
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Ingénieur développement logiciels

    Informations forums :
    Inscription : Décembre 2009
    Messages : 38
    Points : 61
    Points
    61
    Par défaut
    Bonjour,

    Personnellement, je viens de tester le code suivant (peu de modification par rapport au tiens) et je n'ai pas d'erreurs.

    Code java : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
     
    		try {
    			String server = "XXXX";
    			String username = "XXXX";
    			String password = "XXXX";
     
    			// Connect and logon to FTP Server
     
    			FTPClient ftp = new FTPClient();
    			ftp.connect(server);
    			ftp.login(username, password);
    			System.out.println("Connected to " + server + ".");
    			System.out.print(ftp.getReplyString());
     
    			// List the files in the directory
    			ftp.changeWorkingDirectory("./test");
     
    			FTPFile[] files = ftp.listFiles();
    			System.out.println("Number of files in dir: " + files.length);
    			DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT);
    			for (int i = 0; i < files.length; i++) {
    				System.out.print(df.format(files[i].getTimestamp().getTime()));
    				System.out.println("\t" + files[i].getName());
    			}
    			ftp.logout();
    			ftp.disconnect();
     
    		} catch (Exception e) {
    			e.printStackTrace();
    		}

    J'ai également testé avec cette ligne là :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    ftp.changeWorkingDirectory("/");
    Et la fonction me renvoi toujours une liste correcte. Il se peut que la configuration du côté du serveur bloque la fonction de listage des fichiers (j'avoue ne pas savoir si c'est possible). Je te conseillerais comme BenWillard de voir du côté des logs serveur afin d'avoir plus d'information.

  5. #5
    Membre éclairé Avatar de JoeChip
    Profil pro
    Inscrit en
    Septembre 2008
    Messages
    536
    Détails du profil
    Informations personnelles :
    Localisation : Belgique

    Informations forums :
    Inscription : Septembre 2008
    Messages : 536
    Points : 803
    Points
    803
    Par défaut
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
            FTPFile[] files = ftp.listFiles();
            for (int i = 0; i < files.length; i++) {
                    System.out.print(df.format(files[i].getTimestamp().getTime()));
    		System.out.println("\t" + files[i].getName());
    	}
    est plus simple comme ça :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    	FTPFile[] files = ftp.listFiles();
            for (FTPFile file : files) 
                    System.out.println(df.format(file.getTimestamp().getTime()) +"\t" + file.getName());
    Moi j'irais même à :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    	for (FTPFile file : ftp.listFiles()) 
                    System.out.println(df.format(file.getTimestamp().getTime()) +"\t" + file.getName());
    pour simplifier encore, mais uniquement, bien sûr, si je ne veux faire que le println...

  6. #6
    Membre à l'essai
    Homme Profil pro
    Développeur .NET
    Inscrit en
    Mai 2010
    Messages
    17
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Nord (Nord Pas de Calais)

    Informations professionnelles :
    Activité : Développeur .NET

    Informations forums :
    Inscription : Mai 2010
    Messages : 17
    Points : 16
    Points
    16
    Par défaut
    Bonjour,
    Après avoir essayé avec un autre FTP (qui me retourne une fois de plus la même erreur), je me demande si sa ne serai pas ma box ou un pare feu quelconque qui pourrai bloquer cette commande.Donc si quelqu'un a une idée car la je m'arrache les cheveux depuis un mois dessus...
    (en sachant que en passant directement par une page web, j'y accède sans problème).

    Merci pour vos réponse!

  7. #7
    Membre éclairé Avatar de JoeChip
    Profil pro
    Inscrit en
    Septembre 2008
    Messages
    536
    Détails du profil
    Informations personnelles :
    Localisation : Belgique

    Informations forums :
    Inscription : Septembre 2008
    Messages : 536
    Points : 803
    Points
    803
    Par défaut
    Pour la 3ème fois : il y a quoi sur les logs du serveur ?

  8. #8
    Membre à l'essai
    Homme Profil pro
    Développeur .NET
    Inscrit en
    Mai 2010
    Messages
    17
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Nord (Nord Pas de Calais)

    Informations professionnelles :
    Activité : Développeur .NET

    Informations forums :
    Inscription : Mai 2010
    Messages : 17
    Points : 16
    Points
    16
    Par défaut
    euh, que voulez vous dire par log?
    En principe les log des serveurs ne sont pas disponible aux utilisateurs, non?

  9. #9
    Membre à l'essai
    Homme Profil pro
    Développeur .NET
    Inscrit en
    Mai 2010
    Messages
    17
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Nord (Nord Pas de Calais)

    Informations professionnelles :
    Activité : Développeur .NET

    Informations forums :
    Inscription : Mai 2010
    Messages : 17
    Points : 16
    Points
    16
    Par défaut
    Bonjour,
    Grâce à TYPSoft FTP Server , j'ai fait mon propre serveur ftp pour tester:
    Le programme se bloque toujours au même endroit:
    FTPFile[] files = ftp.listFiles();

    Et voici les logs du serveur:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
     
    [2011-10-18 - 18:33:07] - [36] Connect to ***.***.***.***. Get Username.
    [2011-10-18 - 18:33:07] - [36] KEYWORD: USER -- PARAMS: login
    [2011-10-18 - 18:33:07] - [36] KEYWORD: PASS -- PARAMS:  #####
    [2011-10-18 - 18:33:07] - [36] User login Connected
    [2011-10-18 - 18:33:07] - [36] login: Current Directory: D:\ftp\
    [2011-10-18 - 18:33:07] - [36] KEYWORD: SYST -- PARAMS: 
    [2011-10-18 - 18:33:07] - [36] Client login, ***.***.***.*** Disconnected (00:00:00 Min)

    J'espère que c'est ceci qu'il vous fallait.
    Merci d'avance

  10. #10
    Membre du Club
    Profil pro
    Inscrit en
    Novembre 2005
    Messages
    56
    Détails du profil
    Informations personnelles :
    Localisation : Belgique

    Informations forums :
    Inscription : Novembre 2005
    Messages : 56
    Points : 49
    Points
    49
    Par défaut
    Bonjour,

    As-tu essayé de te connecter en mode passif?
    Méthode enterLocalPassiveMode() de la classe FTPCLient

    Sam

  11. #11
    Membre à l'essai
    Homme Profil pro
    Développeur .NET
    Inscrit en
    Mai 2010
    Messages
    17
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Nord (Nord Pas de Calais)

    Informations professionnelles :
    Activité : Développeur .NET

    Informations forums :
    Inscription : Mai 2010
    Messages : 17
    Points : 16
    Points
    16
    Par défaut
    Bonjour,
    Désolé pour la réponse très tardive (soucis personnel...)
    J'ai testé la méthode passive et celà ne change rien.
    Par contre j'ai utilisé la commande listHelp() qui me retourne ce resultat:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
     
    214-The following commands are recognized (* =>'s unimplemented):
     CWD     XCWD    CDUP    XCUP    SMNT*   QUIT    PORT    PASV    
     EPRT    EPSV    ALLO*   RNFR    RNTO    DELE    MDTM    RMD     
     XRMD    MKD     XMKD    PWD     XPWD    SIZE    SYST    HELP    
     NOOP    FEAT    OPTS    AUTH    CCC*    CONF*   ENC*    MIC*    
     PBSZ    PROT    TYPE    STRU    MODE    RETR    STOR    STOU    
     APPE    REST    ABOR    USER    PASS    ACCT*   REIN*   LIST    
     NLST    STAT    SITE    MLSD    MLST    
    214 Direct comments to root@***.***.***.***
    et la commande listNames() ne me retourne strictement rien...

    Merci de votre aide
    Bonne après midi a tous

  12. #12
    Membre à l'essai
    Homme Profil pro
    Développeur .NET
    Inscrit en
    Mai 2010
    Messages
    17
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Nord (Nord Pas de Calais)

    Informations professionnelles :
    Activité : Développeur .NET

    Informations forums :
    Inscription : Mai 2010
    Messages : 17
    Points : 16
    Points
    16
    Par défaut
    Je remonte un de mes anciens sujets au cas où des personnes auraient le même problème...
    Après avoir formaté mon PC, j'ai réessayer mon code et là: miracle tout fonctionne...
    Donc si quelqu'un a une idée d'où cela a pu venir je suis preneur et je pense que d'autre le serait aussi...
    En attendant c'est un sujet résolut...

  13. #13
    Membre éclairé Avatar de JoeChip
    Profil pro
    Inscrit en
    Septembre 2008
    Messages
    536
    Détails du profil
    Informations personnelles :
    Localisation : Belgique

    Informations forums :
    Inscription : Septembre 2008
    Messages : 536
    Points : 803
    Points
    803
    Par défaut
    On ne peut plus à présent faire que des hypothèses : les informations ont disparu, sauf.... sur les logs du serveur

    Ca peut être :

    - un firewall, un socket, un driver ou tout au programme impliqué mal configuré ou ayant subi un "impact", genre passage par un bug ou un virus et/ou avec un fichier faiblement endommagé, genre pas assez pour le planter vraiment, mais assez pour le faire foirer subtilement
    - une modification dans une option obscure, concernant l'un ou l'autre timeout, par un programme qui n'a pas été réinstallé sur la nouvelle config (pour le moment...?) ou par un virus, un bug, etc
    - autre chose qui n'a rien à voir.

    Cela dit, ça me dit quelque chose, ton truc. Dans ces cas-là, le mieux c'est de tester sur un serveur ftp local, pour avoir ** les logs du serveur **

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Problème téléchargement FTP ligne de commande
    Par shu_sama dans le forum Windows
    Réponses: 2
    Dernier message: 28/02/2013, 13h51
  2. Réponses: 6
    Dernier message: 29/05/2007, 17h41
  3. Problème lors du téléchargement FTP avec FTPClient
    Par Shuret dans le forum Entrée/Sortie
    Réponses: 1
    Dernier message: 12/04/2007, 16h16
  4. [Windows 2000 server] Téléchargement FTP impossible sous IE6
    Par o151181 dans le forum Windows Serveur
    Réponses: 6
    Dernier message: 24/11/2004, 18h00

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo