File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes how can we connect to unix server using java program Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "how can we connect to unix server using java program" Watch "how can we connect to unix server using java program" New topic

how can we connect to unix server using java program

suresh varthi

Joined: Jun 03, 2008
Posts: 1
Hi ,

I have an application in which i have to connect to unix server from a java program by providing the details ip and ID/password with in the java program(i:e the java program should ask for user id and password again) and the i need to do fallowing activities

1) run a script.
2) move to some other location.
3) removing files......etc

is it possible to do so from a java program...

Please respond for this....

thanks in advance.\

Rob Spoor

Joined: Oct 27, 2005
Posts: 20279

Connect how? Are you talking about telnet or SSH?

If so, Apache Commons Net has a telnet client, or you can find several libraries using Google, like JSch.

How To Ask Questions How To Answer Questions
jiju ka
Ranch Hand

Joined: Oct 12, 2004
Posts: 306
runtime = Runtime.getRuntime() // to get runtime

Then use runtime.exec("command here");

You may use System.getProperty() to identify OS.
[ June 12, 2008: Message edited by: jiju ka ]
Ernest Friedman-Hill
author and iconoclast

Joined: Jul 08, 2003
Posts: 24199

Originally posted by jiju ka:
runtime = Runtime.getRuntime() // to get runtime

This would help you run something on the server if your code is running on the server, which I don't think is the case here. The solution about telnet or ssh libraries is more appropriate. Although technically, you could potentially use Runtime.exec() to execute a local ssh process which connects to the remove machine and executes a command. The solution using an ssh library would be far more portable and more efficient.

[Jess in Action][AskingGoodQuestions]
I agree. Here's the link:
subject: how can we connect to unix server using java program
It's not a secret anymore!