• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Access unix machine to read and save a file

 
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 41
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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

 
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 41
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Hi Rob Spoor,
I referred to your reply in the below link
https://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: 41
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 41
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 41
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All ,
i am not able to access unix machine using your steps
can somebody help me
 
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
reply
    Bookmark Topic Watch Topic
  • New Topic