File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Sockets and Internet Protocols and the fly likes Access unix machine to read and save a file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Sockets and Internet Protocols
Bookmark "Access unix machine to read and save a file" Watch "Access unix machine to read and save a file" New topic
Author

Access unix machine to read and save a file

Archana Honnavalli
Ranch Hand

Joined: Feb 26, 2008
Posts: 39
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

Joined: Feb 26, 2008
Posts: 39
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

Joined: Oct 27, 2005
Posts: 19544
    
  16

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.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Archana Honnavalli
Ranch Hand

Joined: Feb 26, 2008
Posts: 39

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

Joined: Feb 26, 2008
Posts: 39
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

Joined: Oct 27, 2005
Posts: 19544
    
  16

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

Joined: Feb 26, 2008
Posts: 39
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

Joined: Feb 26, 2008
Posts: 39
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

Joined: Apr 22, 2009
Posts: 22
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.


to infinity and beyond
yamini chopra
Greenhorn

Joined: Jun 03, 2013
Posts: 1
Hi All ,
i am not able to access unix machine using your steps
can somebody help me
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

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).
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Access unix machine to read and save a file
 
Similar Threads
What IP address do i use.
Loadjava program
Access unix machine to read and save a file- from java code - Unix machine IP, userID, pwd given
How to update a database using web forms
How I connect to remote Unix Box from standalone java application?