C
Carlos
Hi, anyone can help me?
I'm working on windows and I want to execute a command on a remote
computer (Unix) so I try to make a telnet to the specified server but
I didn't get any answer. My code is really simple. I DON'T WANT TO USE
SOCKETS OR ANY OTHER PROGRAM IN THE SERVER.
Can anyone give some advice, or any suggestion?
SOURCE CODE (this is the source code that I'm using)
-------------------------
import java.io.*;
class test{
public test(){}
public void process(){
try {
// Execute command
String command = "telnet";
Process child = Runtime.getRuntime().exec(command);
OutputStream out = child.getOutputStream();
out.write("open <SERVER_NAME>\n".getBytes());
// Get the input stream and read from it
InputStream in = child.getInputStream();
int c;
while ((c = in.read()) != -1) {
System.out.print(""+(char)c);
}
out.write("my_user\n".getBytes());
while ((c = in.read()) != -1) {
System.out.print(""+(char)c);
}
out.write("\n".getBytes());
while ((c = in.read()) != -1) {
System.out.print(""+(char)c);
}
out.write("touch carlos.txt".getBytes());
out.write("exit".getBytes());
in.close();
out.close();
} catch (IOException e) { System.out.println(e.getMessage());
}
}
public static void main(String args[]){
test uno = new test();
uno.process();
}
}
I'm working on windows and I want to execute a command on a remote
computer (Unix) so I try to make a telnet to the specified server but
I didn't get any answer. My code is really simple. I DON'T WANT TO USE
SOCKETS OR ANY OTHER PROGRAM IN THE SERVER.
Can anyone give some advice, or any suggestion?
SOURCE CODE (this is the source code that I'm using)
-------------------------
import java.io.*;
class test{
public test(){}
public void process(){
try {
// Execute command
String command = "telnet";
Process child = Runtime.getRuntime().exec(command);
OutputStream out = child.getOutputStream();
out.write("open <SERVER_NAME>\n".getBytes());
// Get the input stream and read from it
InputStream in = child.getInputStream();
int c;
while ((c = in.read()) != -1) {
System.out.print(""+(char)c);
}
out.write("my_user\n".getBytes());
while ((c = in.read()) != -1) {
System.out.print(""+(char)c);
}
out.write("\n".getBytes());
while ((c = in.read()) != -1) {
System.out.print(""+(char)c);
}
out.write("touch carlos.txt".getBytes());
out.write("exit".getBytes());
in.close();
out.close();
} catch (IOException e) { System.out.println(e.getMessage());
}
}
public static void main(String args[]){
test uno = new test();
uno.process();
}
}