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

  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 : 45
    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 : 45
    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.

  7. #7
    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 : 45
    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
    Citation Envoyé par astrotouf Voir le message
    Je me demande ce que c'est que ce : Algorithm negotiation fail
    A priori, l'algorithme d'encryptage (qui doit etre négocié entre ceux supportés par le serveur et ceux supportés par le client).
    quand tu parles du Home, c'est celui du serveur ? Parceque moi je suis sous Windows.
    Non, celui du client.

    Ton serveur sftp tourne bien sur du ssh2, pas du ssh1? Parce que ces outils sont généralement prévue pour le ssh2

  8. #8
    Expert confirmé
    Avatar de Marco46
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Août 2005
    Messages
    4 419
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 43
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Août 2005
    Messages : 4 419
    Par défaut
    Citation Envoyé par astrotouf Voir le message
    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.
    Ca veut dire que le client et le serveur n'ont aucun algorithme de chiffrement supportés en commun. D'où le dialogue impossible. Le client ou le serveur doit être dans une vieille version.

    Tu peux voir les algos supportés dans les certificats de ton client et de ton serveur. C'est cette base d'information qui est utilisée lors du handshake pour savoir lequel des algos va être utilisé. Attention il y a 2 algos différents utilisés lors d'un tel dialogue, un algo asymétrique (RSA) pour échanger la clef de session qui sera utilisée par un algo symétrique (AES).

  9. #9
    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
    2009-11-06 16:33:20 Looking up host "10.10.10.5"
    2009-11-06 16:33:20 Connecting to 10.206.54.67 port 22
    2009-11-06 16:33:20 Server version: SSH-2.0-OpenSSH_5.0
    2009-11-06 16:33:20 We claim version: SSH-2.0-PuTTY_Release_0.60
    2009-11-06 16:33:20 Using SSH protocol version 2
    2009-11-06 16:33:20 Doing Diffie-Hellman group exchange
    2009-11-06 16:33:20 Doing Diffie-Hellman key exchange with hash SHA-256
    2009-11-06 16:33:21 Host key fingerprint is:
    2009-11-06 16:33:21 ssh-rsa 2048 be:0b:b3:08:21:89:bb:12:11:42:d8:b3:7d:66:45:e8
    2009-11-06 16:33:21 Initialised AES-256 SDCTR client->server encryption
    2009-11-06 16:33:21 Initialised HMAC-SHA1 client->server MAC algorithm
    2009-11-06 16:33:21 Initialised AES-256 SDCTR server->client encryption
    2009-11-06 16:33:21 Initialised HMAC-SHA1 server->client MAC algorithm
    2009-11-06 16:33:21 Keyboard-interactive authentication refused
    2009-11-06 16:33:24 Sent password
    2009-11-06 16:33:24 Access granted
    2009-11-06 16:33:24 Opened channel for session
    2009-11-06 16:33:24 Allocated pty (ospeed 38400bps, ispeed 38400bps)
    2009-11-06 16:33:24 Started a shell/command



    J'ai pu avoir les infos du serveur. Maintenant comment adapter JSCh à ces paramètres ?
    Dans les caratéristiques de JSCh il mettent :

    Cipher: blowfish-cbc,3des-cbc,aes128-cbc,aes192-cbc,aes256-cbc
    3des-ctr,aes128-ctr,aes192-ctr,aes256-ctc,
    arcfour,arcfour128,arcfour256

    or, je constate que mon serveur utilise AES-256 SDCTR.
    Peut être que c'est ça ? Vous en pensez quoi ?

    Citation Envoyé par tchize_ Voir le message
    Non, celui du client.
    Je suis sous Windows et j'utilise une librairie Java. Donc je ne trouve pas ce fichier.

  10. #10
    Expert confirmé
    Avatar de Marco46
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Août 2005
    Messages
    4 419
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 43
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Août 2005
    Messages : 4 419
    Par défaut
    Ton /home/user sous Windows c'est C:\Documents and Settings\user

    Pour en revenir à ton problème, c'est bien une histoire d'algos de chiffrements incompatibles.

    Il ne suffit pas d'avoir des algos identiques, en l'occurrence ici AES-256bits mais également d'utiliser les mêmes modes.

    A propos de la lib SSHTools, à ce que je vois sur sourceforge, il n'y a plus eu de mise à jour depuis 2007 et à ce que je vois dans le dossier lib de J2SSH, la version de BouncyCastle fournissant les implémentations des algos de chiffrement date d'il y a un bail. Sans parler de la version du JRE (1.3).

    Donc bon, je ne sais pas s'il y a d'autres lib pour SSH en java mais je te suggère d'utiliser quelque chose de + récent et surtout de maintenu à jour.

    Pour JSch, je constate ici que dans la section features l'algo AES avec le bon mode est supporté : aes256-ctr

    Tu as très probablement un système pour imposer cet algo comme algo préféré mais logiquement il aurait du se débrouiller tout seul lors du handshake.

  11. #11
    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
    J'ai trouvé le : C:\Documents and Settings\astrotouf\.ssh\known_hosts

    merci pour ça.

    j'ai trouvé un topic où la personne a exactement le même problème que moi :
    http://www.coderanch.com/t/465478/So...-using#2101591

    c'est en Anglais.

    Je vais continuer à chercher une autre librairie mais j'aimerai vraiment que celle-ci fonctionne.

  12. #12
    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
    Salut à tous. Histoire de fermer ce topic une bonne fois pour toutes. Je me suis tourné vers une API qui se nomme Ganymed SSH-2 for Java.
    Et cela a fonctionné du tonnerre sans aucune intervention de ma part.
    voici le lien pour télécharger le jar :
    http://www.ganymed.ethz.ch/ssh2/

    et voici le code à utiliser :
    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
     
    import java.io.BufferedReader;
    //import java.io.IOException;
    import java.io.InputStream;
    import java.io.InputStreamReader;
    //import java.io.Serializable;
     
    import ch.ethz.ssh2.Connection;
    import ch.ethz.ssh2.Session;
    import ch.ethz.ssh2.StreamGobbler;
     
    public class MainClass {
     
    	/**
             * @param args
             */
    	public static void main(String[] args) {
    		// TODO Auto-generated method stub
    		String hostname = new String("127.0.0.1");
    		String user = new String("user");
    		String password = new String("motdepasse");
    		String encoding = new String("UTF-8");
    		Connection connection;
    		Session session;
    		try {
     
    			// piverture de la connexion
    			connection = new Connection(hostname);
    			connection.connect();
    			boolean isAuthenticated = connection.authenticateWithPassword(user,
    					password);
    			if (isAuthenticated == false) {
    				throw new Exception("Authentication failed.");
    			}
    			session = connection.openSession();
     
    			// execution de quelques commandes
    			String cmd = new String("pwd");
    			System.out.println("exec " + cmd);
    			session.execCommand(cmd);
    			InputStream stdout = new StreamGobbler(session.getStdout());
    			BufferedReader br = new BufferedReader(new InputStreamReader(
    					stdout, encoding));
    			System.out.println("Résultat :");
    			while (true) {
    				String line = br.readLine();
    				if (line == null) {
    					break;
    				}
    				System.out.println(line);
    			}
     
    			// Fermeture de la session et connexion
    			session.close();
    			System.out.println("Disconnect...");
    			connection.close();
    			System.out.println("Disconnected");
     
    		} catch (Exception e) {
    			e.printStackTrace();
    		}
     
    	}
     
    }
    Voilà j'espère que ça aidera quelqu'un.

    Bon courage à tous.

+ 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