Bonjour,
Je souhaite envoyer des commandes SSH dans une console Putty via un programme Java.
Pour cela j'ai lu qu'on pouvait utiliser plink : http://marc.terrier.free.fr/docputty/Chapter7.html
Mais j'ai un souci, je n'arrive pas à lancer quoi que ce soit et je me demandais si on pouvais avoir un exemple d'utilisation.
Voilà où j'en suis, je lance ce code :
Et j'ai ça en console, sauf que ça ne veut rien dire :
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 import java.io.InputStream; import java.io.OutputStream; public class Main { private static InputStream std; private static OutputStream out; private static InputStream err; public static void main(String[] args) { try { String command = "plink -load profile"; Runtime r = Runtime.getRuntime (); Process p = r.exec (command); std = p.getInputStream (); out = p.getOutputStream (); err = p.getErrorStream (); out.write ("ls -l\n".getBytes ()); out.flush (); Thread.sleep (1000); int value = 0; if (std.available () > 0) { System.out.println ("STD:"); value = std.read (); System.out.print ((char) value); while (std.available () > 0) { value = std.read (); System.out.print ((char) value); } } if (err.available () > 0) { System.out.println ("ERR:"); value = err.read (); System.out.print ((char) value); while (err.available () > 0) { value = err.read (); System.out.print ((char) value); } } p.destroy (); } catch (Exception e) { e.printStackTrace (); } } }
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 STD: Plink: command-line connection utility Release 0.64 Usage: plink [options] [user@]host [command] ("host" can also be a PuTTY saved session name) Options: -V print version information and exit -pgpfp print PGP key fingerprints and exit -v show verbose messages -load sessname Load settings from saved session -ssh -telnet -rlogin -raw -serial force use of a particular protocol -P port connect to specified port -l user connect with specified username -batch disable all interactive prompts -sercfg configuration-string (e.g. 19200,8,n,1,X) Specify the serial configuration (serial only) The following options only apply to SSH connections: -pw passw login with specified password -D [listen-IP:]listen-port Dynamic SOCKS-based port forwarding -L [listen-IP:]listen-port:host:port Forward local port to remote address -R [listen-IP:]listen-port:host:port Forward remote port to local address -X -x enable / disable X11 forwarding -A -a enable / disable agent forwarding -t -T enable / disable pty allocation -1 -2 force use of particular protocol version -4 -6 force use of IPv4 or IPv6 -C enable compression -i key private key file for user authentication -noagent disable use of Pageant -agent enable use of Pageant -hostkey aa:bb:cc:... manually specify a host key (may be repeated) -m file read remote command(s) from file -s remote command is an SSH subsystem (SSH-2 only) -N don't start a shell/command (SSH-2 only) -nc host:port open tunnel in place of session (SSH-2 only)
Partager