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

Sécurité Java Discussion :

The socket is EOF : J2SSH


Sujet :

Sécurité Java

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre éclairé Avatar de astrotouf
    Profil pro
    Consultant informatique
    Inscrit en
    Avril 2005
    Messages
    221
    Détails du profil
    Informations personnelles :
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Consultant informatique

    Informations forums :
    Inscription : Avril 2005
    Messages : 221
    Par défaut The socket is EOF : J2SSH
    Bonjour à tous. Je viens de découvrir une API qui me semble intéressante qui se nomme J2SSH (sshtools) que vous pouvez trouver ici : http://sourceforge.net/projects/sshtools/.
    mon problème est que j'ai fait un petit programme :
    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
    import java.io.FileInputStream;
     
    import com.sshtools.j2ssh.SshClient;
    import com.sshtools.j2ssh.authentication.AuthenticationProtocolState;
    import com.sshtools.j2ssh.authentication.PasswordAuthenticationClient;
     
    public class MainClass {
     
    	/**
             * @param args
             */
    	public static void main(String[] args) {
    		// TODO Auto-generated method stub
    		String hostname = new String("10.20.10.15");
    		String username = new String("admin");
    		String password = new String("password");
     
    		SshClient ssh = new SshClient();
    		try {
     
    			ssh.connect(hostname, 22);
    			//Authenticate
    			PasswordAuthenticationClient passwordAuthenticationClient = new PasswordAuthenticationClient();
    			passwordAuthenticationClient.setUsername(username);
    			passwordAuthenticationClient.setPassword(password);
    			int result = ssh.authenticate(passwordAuthenticationClient);
     
    			ssh.disconnect();
     
    			System.out.println("Disconnect...");
     
    		} catch (Exception e) {
    			System.out.println("L'exception suivante s'est produite : "
    					+ e.getLocalizedMessage());
    		}
    	}
    }
    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
    55
    56
    57
    58
    59
     
    5 nov. 2009 13:03:37 com.sshtools.j2ssh.transport.cipher.SshCipherFactory <clinit>
    INFO: Loading supported cipher algorithms
    5 nov. 2009 13:03:37 com.sshtools.j2ssh.transport.kex.SshKeyExchangeFactory <clinit>
    INFO: Loading key exchange methods
    5 nov. 2009 13:03:37 com.sshtools.j2ssh.configuration.ConfigurationLoader initialize
    INFO: JAVA version is 1.6.0_15
    5 nov. 2009 13:03:37 com.sshtools.j2ssh.configuration.ConfigurationLoader initialize
    INFO: Extension C:\Program Files\Java\jre6\lib\ext\dnsns.jar being added to classpath
    5 nov. 2009 13:03:37 com.sshtools.j2ssh.util.ExtensionClassLoader add
    INFO: Adding C:\Program Files\Java\jre6\lib\ext\dnsns.jar to the extension classpath
    5 nov. 2009 13:03:37 com.sshtools.j2ssh.configuration.ConfigurationLoader initialize
    INFO: Extension C:\Program Files\Java\jre6\lib\ext\localedata.jar being added to classpath
    5 nov. 2009 13:03:37 com.sshtools.j2ssh.util.ExtensionClassLoader add
    INFO: Adding C:\Program Files\Java\jre6\lib\ext\localedata.jar to the extension classpath
    5 nov. 2009 13:03:37 com.sshtools.j2ssh.configuration.ConfigurationLoader initialize
    INFO: Extension C:\Program Files\Java\jre6\lib\ext\sunjce_provider.jar being added to classpath
    5 nov. 2009 13:03:37 com.sshtools.j2ssh.util.ExtensionClassLoader add
    INFO: Adding C:\Program Files\Java\jre6\lib\ext\sunjce_provider.jar to the extension classpath
    5 nov. 2009 13:03:37 com.sshtools.j2ssh.configuration.ConfigurationLoader initialize
    INFO: Extension C:\Program Files\Java\jre6\lib\ext\sunmscapi.jar being added to classpath
    5 nov. 2009 13:03:37 com.sshtools.j2ssh.util.ExtensionClassLoader add
    INFO: Adding C:\Program Files\Java\jre6\lib\ext\sunmscapi.jar to the extension classpath
    5 nov. 2009 13:03:37 com.sshtools.j2ssh.configuration.ConfigurationLoader initialize
    INFO: Extension C:\Program Files\Java\jre6\lib\ext\sunpkcs11.jar being added to classpath
    5 nov. 2009 13:03:37 com.sshtools.j2ssh.util.ExtensionClassLoader add
    INFO: Adding C:\Program Files\Java\jre6\lib\ext\sunpkcs11.jar to the extension classpath
    5 nov. 2009 13:03:37 com.sshtools.j2ssh.transport.publickey.SshKeyPairFactory <clinit>
    INFO: Loading public key algorithms
    5 nov. 2009 13:03:37 com.sshtools.j2ssh.transport.compression.SshCompressionFactory <clinit>
    INFO: Loading compression methods
    5 nov. 2009 13:03:37 com.sshtools.j2ssh.transport.hmac.SshHmacFactory <clinit>
    INFO: Loading message authentication methods
    5 nov. 2009 13:03:37 com.sshtools.j2ssh.transport.TransportProtocolCommon startTransportProtocol
    INFO: Starting transport protocol
    5 nov. 2009 13:03:37 com.sshtools.j2ssh.transport.TransportProtocolCommon run
    INFO: Registering transport protocol messages with inputstream
    5 nov. 2009 13:03:38 com.sshtools.j2ssh.transport.TransportProtocolCommon negotiateVersion
    INFO: Negotiating protocol version
    5 nov. 2009 13:03:38 com.sshtools.j2ssh.transport.TransportProtocolCommon negotiateVersion
    INFO: Protocol negotiation complete
    5 nov. 2009 13:03:38 com.sshtools.j2ssh.transport.TransportProtocolCommon beginKeyExchange
    INFO: Starting key exchange
    5 nov. 2009 13:03:38 com.sshtools.j2ssh.transport.kex.DhGroup1Sha1 performClientExchange
    INFO: Starting client side key exchange.
    5 nov. 2009 13:03:38 com.sshtools.j2ssh.transport.TransportProtocolCommon run
    GRAVE: The Transport Protocol thread failed
    java.io.IOException: The socket is EOF
    	at com.sshtools.j2ssh.transport.TransportProtocolInputStream.readBufferedData(Unknown Source)
    	at com.sshtools.j2ssh.transport.TransportProtocolInputStream.readMessage(Unknown Source)
    	at com.sshtools.j2ssh.transport.TransportProtocolCommon.readMessage(Unknown Source)
    	at com.sshtools.j2ssh.transport.kex.DhGroup1Sha1.performClientExchange(Unknown Source)
    	at com.sshtools.j2ssh.transport.TransportProtocolClient.performKeyExchange(Unknown Source)
    	at com.sshtools.j2ssh.transport.TransportProtocolCommon.beginKeyExchange(Unknown Source)
    	at com.sshtools.j2ssh.transport.TransportProtocolCommon.onMsgKexInit(Unknown Source)
    	at com.sshtools.j2ssh.transport.TransportProtocolCommon.startBinaryPacketProtocol(Unknown Source)
    	at com.sshtools.j2ssh.transport.TransportProtocolCommon.run(Unknown Source)
    	at java.lang.Thread.run(Unknown Source)
    L'exception suivante s'est produite : The socket is EOF
    le problème se situe au niveau de l'instruction :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    ssh.connect(hostname, 22);
    pourtant, j'ai bien inclut tous les Jar nécessaires (inclus dans le package de l'API). J'utilise java 1.6.
    Si quelqu'un a déjà essayé une API qui ne fait pas de problèmes. Je suis partant. Mon but étant d'envoyer et de recevoir des fichiers sur un serveur en utilisant SFTP.
    Merci d'avance pour vos réponses.

  2. #2
    Membre éclairé Avatar de astrotouf
    Profil pro
    Consultant informatique
    Inscrit en
    Avril 2005
    Messages
    221
    Détails du profil
    Informations personnelles :
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Consultant informatique

    Informations forums :
    Inscription : Avril 2005
    Messages : 221
    Par défaut
    Je viens d'intaller java 1.5 et c'est le même problème.

    Personne n'a testé cette librairie ?

  3. #3
    Expert éminent
    Avatar de tchize_
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Avril 2007
    Messages
    25 482
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 46
    Localisation : Belgique

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Avril 2007
    Messages : 25 482
    Par défaut
    Bonjour,

    personellement j'utilise JSch pour l'envoi par sftp. J'ai eu un problème de connection au début qui est peut etre lié au tiens. La clé publique du serveur n'était pas dans mon .ssh/known_host, par conséquent JSch refusait d'aller plus loin dans la connection. C'est peut etre ce que tu as aussi.

  4. #4
    Membre éclairé Avatar de astrotouf
    Profil pro
    Consultant informatique
    Inscrit en
    Avril 2005
    Messages
    221
    Détails du profil
    Informations personnelles :
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Consultant informatique

    Informations forums :
    Inscription : Avril 2005
    Messages : 221
    Par défaut
    Figures-toi que je viens de me lancer dans JSch avec le petit programme suivant :
    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
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    import com.jcraft.jsch.*;
    import java.io.*;
    import java.util.*;
     
    /**
     * This class is used to demonstrate the usage of the JCraft JSch package to
     * SFTP files.
     * 
     * @author Tim Archer 04/20/07
     * @version $Revision: 1.1 $
     */
    public class MainClass {
     
    	/**
             * main - Unit test program
             * 
             * @param args
             *            Command line arguments
             * 
             */
    	public static void main(String args[]) {
    		try {
    			String ftpHost = "10.208.10.54";
    			int ftpPort = 22;
    			String ftpUserName = "user";
    			String ftpPassword = "passw0rd";
    			String ftpRemoteDirectory = "/var/projects/";
    			String fileToTransmit = "c:\\test.txt";
     
    			//
    			// First Create a JSch session
    			//
    			System.out.println("Creating session.");
    			JSch jsch = new JSch();
    			Session session = null;
    			Channel channel = null;
    			ChannelSftp c = null;
     
    			//
    			// Now connect and SFTP to the SFTP Server
    			//
    			try {
    				// Create a session sending through our username and password
    				session = jsch.getSession(ftpUserName, ftpHost, ftpPort);
    				System.out.println("Session created.");
    				session.setPassword(ftpPassword);
    				// Security.addProvider(new com.sun.crypto.provider.SunJCE());
     
    				//
    				// Setup Strict HostKeyChecking to no so we dont get the
    				// unknown host key exception
    				//
    				java.util.Properties config = new java.util.Properties();
    				config.put("StrictHostKeyChecking", "no");
    				session.setConfig(config);
    				session.connect();
    				System.out.println("Session connected.");
     
    				//
    				// Open the SFTP channel
    				//
    				System.out.println("Opening Channel.");
    				channel = session.openChannel("sftp");
    				channel.connect();
    				c = (ChannelSftp) channel;
    			} catch (Exception e) {
    				System.err.println("Unable to connect to FTP server. "
    						+ e.toString());
    				throw e;
    			}
     
    			//
    			// Change to the remote directory
    			//
    			System.out.println("Changing to FTP remote dir: "
    					+ ftpRemoteDirectory);
    			c.cd(ftpRemoteDirectory);
     
    			//
    			// Send the file we generated
    			//  
    			try {
    				File f = new File(fileToTransmit);
    				System.out.println("Storing file as remote filename: "
    						+ f.getName());
    				c.put(new FileInputStream(f), f.getName());
    			} catch (Exception e) {
    				System.err.println("Storing remote file failed. "
    						+ e.toString());
    				throw e;
    			}
     
    			//
    			// Get the list of files in the remote server directory
    			//
    			Vector files = c.ls(ftpRemoteDirectory);
     
    			//
    			// Log if we have nothing to download
    			//
    			if (files.size() == 0) {
    				System.out.println("No files are available for download.");
    			}
    			//
    			// Otherwise download all files except for the . and .. entries
    			//
    			else {
    				for (int i = 0; i < files.size(); i++) {
    					com.jcraft.jsch.ChannelSftp.LsEntry lsEntry = (com.jcraft.jsch.ChannelSftp.LsEntry) files
    							.get(i);
     
    					if (!lsEntry.getFilename().equals(".")
    							&& !lsEntry.getFilename().equals("..")) {
    						System.out.println("Downloading file "
    								+ lsEntry.getFilename());
     
    						String outputFileName = "c:\\temp\\"
    								+ lsEntry.getFilename();
     
    						// Get the write and write it to our local file system
    						File f = new File(outputFileName);
    						c.get(lsEntry.getFilename(), new FileOutputStream(f));
     
    						//
    						// Remove the file from the server
    						//    
    						/*
    						 * c.rm(lsEntry.getFilename());
    						 */
    					}
    				}
    			}
     
    			//
    			// Disconnect from the FTP server
    			//
    			try {
    				c.quit();
    			} catch (Exception exc) {
    				System.err.println("Unable to disconnect from FTP server. "
    						+ exc.toString());
    			}
     
    		} catch (Exception e) {
    			System.err.println("Error: " + e.toString());
    		}
     
    		System.out.println("Process Complete.");
    		System.exit(0);
    	}
    }
    mais j'ai l'erreur suivante :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    Creating session.
    Session created.
    Unable to connect to FTP server. com.jcraft.jsch.JSchException: Algorithm negotiation fail
    Error: com.jcraft.jsch.JSchException: Algorithm negotiation fail
    Process Complete.
    C'est le même problème pour toi ?
    il est où ce .ssh/known_host ?

  5. #5
    Expert éminent
    Avatar de tchize_
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Avril 2007
    Messages
    25 482
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 46
    Localisation : Belgique

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Avril 2007
    Messages : 25 482
    Par défaut
    dans la home, mais j'avais un message d'erreur explicite à propos de la signature RSA du serveur (how key unknown, do you trust it, blablabla)

    T'as essayé avec un autre serveur sftp? T'as essayé en ligne de commande avec un client sftp?

  6. #6
    Membre éclairé Avatar de astrotouf
    Profil pro
    Consultant informatique
    Inscrit en
    Avril 2005
    Messages
    221
    Détails du profil
    Informations personnelles :
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Consultant informatique

    Informations forums :
    Inscription : Avril 2005
    Messages : 221
    Par défaut
    Avec Winscp ou Putty ça marche bien. mais avec Java rien ne semble fonctionner. Je me demande ce que c'est que ce : Algorithm negotiation fail

    On peut modifier l'algorithme ?

    quand tu parles du Home, c'est celui du serveur ? Parceque moi je suis sous Windows.

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

Discussions similaires

  1. Réponses: 4
    Dernier message: 14/04/2010, 11h38
  2. Unable to find the socket transport "ssl"
    Par Invité dans le forum Free
    Réponses: 4
    Dernier message: 01/12/2008, 09h21
  3. executer une application a distance : Sockets ? RPC ? CORBA?
    Par a_hic dans le forum Développement
    Réponses: 5
    Dernier message: 30/05/2006, 13h02
  4. transfert d'un fichier bitmap en socket tcp
    Par localhost dans le forum C++Builder
    Réponses: 5
    Dernier message: 29/07/2002, 00h40

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