This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Access unix machine to read and save a file

 
Archana Honnavalli
Ranch Hand
Posts: 39
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
I have a unix machine in my network
I have its IP - xxx.xxx.xxx.xxx
I have its userID and pwd - uid=uid - pwd=pwd

I need to access this machine from my java class.
I need to read a file from this machine.

PS: I do not want to map the machine on my drive and access it.

Please guide
 
Archana Honnavalli
Ranch Hand
Posts: 39
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Using this approach for the same
Here i am able to connect but telnet.login hangs and eventually "socket exception-connection abort" is shown

But same user id is working if i access unix system extenally

 
Rob Spoor
Sheriff
Pie
Posts: 20372
44
Chrome Eclipse IDE Java Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is a telnet server actually running on the Unix machine? Most system administrators hate telnet because it's insecure, and therefore do not have it installed. They prefer SSH instead.

Also note that, at least as far as I know, telnet does not support file transfer. SSH does, through its SCP protocol.
 
Archana Honnavalli
Ranch Hand
Posts: 39
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Hi Rob Spoor,
I referred to your reply in the below link
http://www.coderanch.com/t/481758/sockets/java/Needs-connect-unix-box-JAVA

Similarly I am using SshWrapper class to connect.
This also uses jta26.jar.
Code mentioned below




I am able to connect to unix box
I am able to login also
But I am getting null at both the System.out.println lines.
Where am i going wrong?
 
Archana Honnavalli
Ranch Hand
Posts: 39
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
From this link
http://javassh.org/download/source/de/mud/ssh/SshWrapper.html#read(byte[])
i understand that
Returns:
output of the command or null if no prompt is set

This i added
ssh.setPrompt("xxx@xxx");
after ssh.login command (after line 4)

Still i m getting present working directory as null in my console
and ls -l is not listing files the given location, but returning null in console.

Any idea?
 
Rob Spoor
Sheriff
Pie
Posts: 20372
44
Chrome Eclipse IDE Java Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What happens if you don't send the "cd //location//" command? Because then your example looks almost identical to the example on that page, except for the different waitfor symbol.
 
Archana Honnavalli
Ranch Hand
Posts: 39
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tried with this.
Commented line 6 and line 8
Still getting null at line 7

Also eventually i need to access cd //location//
Because i need to access files in that directory.

 
Archana Honnavalli
Ranch Hand
Posts: 39
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
One more doubt after parsing line 4



console prints lot of information like addpayload2 1, packet len, ssh info.

This i dont see when i login from telnet window
That is cmd prompt
Give command- telnet IP
Telnet window opens and prompts for uid and pwd.
After this no such information is shown.

What is this?

P.S: New to unix

Thanks
Archana
 
Eric Mission
Greenhorn
Posts: 22
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Archana, I've never used the SshWrapper class before so I can't comment on the error you are having but I am curious as to why you don't just use an SSH client. There are several freely available ones out there. I personally use PuTTy which has telnet, ssh and more.

I did some searching on this class and found a link to the SOURCE. I noticed that the class is using a basic socket to connect. As I mentioned before I'm not familiar with the API other than just reading the source but to me that generic socket connection may be your problem if it isn't taking permission into account. If the SshWrapper class does not account for permissions on the machine you are trying to access then that may explain why you are getting NULL when you send a command. In other words, the Unix machine may permit you to do a remote SSH connection but may forbid you from changing directories or running other commands.

I am guessing that you want to just issue a



or a



to the server and you can't even change directories (remote access permission block?).


My recommendations: 1) I would try to create my own custom socket server/client application that would read the files or even transfer them locally for reading 2) use an SSH client.

Hope that helps.
 
yamini chopra
Greenhorn
Posts: 1
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All ,
i am not able to access unix machine using your steps
can somebody help me
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yamini chopra wrote:Hi All ,
i am not able to access unix machine using your steps
can somebody help me


Hi, and welcome to the Ranch!

Please start your own thread.

TellTheDetails(⇐click). Tell us exactly what you tried and exactly what went wrong. So far, you're just saying, "It doesn't work," but ItDoesntWorkIsUseless(←click).
 
Don't get me started about those stupid light bulbs.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic