aspose file tools*
The moose likes Java in General and the fly likes Connecting two linux machines using smb Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Connecting two linux machines using smb" Watch "Connecting two linux machines using smb" New topic
Author

Connecting two linux machines using smb

Naresh Kavala
Greenhorn

Joined: Jun 07, 2008
Posts: 23
Hello Ranchers,

Could anybody please explain or post some code how to access a remote linux file from an application deployed in another linux server using SMB protocol.

Regards,
Naresh.
Wim Vanni
Ranch Hand

Joined: Apr 06, 2011
Posts: 96

Sounds like a very broad question to which in most cases people will tend to answer: go and read the manual, the tutorial, the documentation and whatnot. Have you tried anything yourself? Encountered specific problems? Are you sure your requirements force you to make use of smb? Could there be other possibilities? HTTP perhaps?

Cheers,
Wim
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19697
    
  20

Check out JCIFS; it makes it a lot easier to work with SMB shares.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Naresh Kavala
Greenhorn

Joined: Jun 07, 2008
Posts: 23
Wim Vanni wrote:Sounds like a very broad question to which in most cases people will tend to answer: go and read the manual, the tutorial, the documentation and whatnot. Have you tried anything yourself? Encountered specific problems? Are you sure your requirements force you to make use of smb? Could there be other possibilities? HTTP perhaps?

Cheers,
Wim


Hi Wim,

Thanks for the reply . I have tried above scenario using Sftp protocol.
Here we are trying to connect using sftp protocol. Please check code to connect below. The connection is getting established but while reading the data we are getting NoSuchMethodError even though required method is found in the jar. Same error is not reproducible when we deploy the application in Windows server.

Connection Code :
uri = "sftp://" + Constants.MONITOR_SERVER_UNIXUSERID + ":" + Constants.MONITOR_SERVER_UNIXPASSWORD + "@"
+ server IP+Constants.MONITOR_SERVER_UNIXFILEPATH+"IIS
linuxFileName = getLatestMonValFileFromLinux(Constants.MONITOR_SERVER_UNIXUSERID, Constants.MONITOR_SERVER_UNIXPASSWORD, instanceName, Constants.port, Constants.MONITOR_SERVER_UNIXFILEPATH+"IIS/");

FileObject fo = fsManager.resolveFile(completeURL.trim(), fsOptions);
if(fo.getContent() !=null){ -------- At this point, while reading data following exception is occurring.
Exception details :
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
………………………………………………………………………..
………………………………………………………………………..
Caused by: java.lang.NoSuchMethodError: com.jcraft.jsch.ChannelSftp.isClosed()Z
at org.apache.commons.vfs.provider.sftp.SftpFileSystem.putChannel(SftpFileSystem.java:158)
at org.apache.commons.vfs.provider.sftp.SftpFileObject.statSelf(SftpFileObject.java:148)
at org.apache.commons.vfs.provider.sftp.SftpFileObject.doGetType(SftpFileObject.java:75)
at org.apache.commons.vfs.provider.AbstractFileObject.attach(AbstractFileObject.java:1296)
at org.apache.commons.vfs.provider.AbstractFileObject.getContent(AbstractFileObject.java:1041)

Lot of experiments but no use. So I thought to use smb protocal but I am not able to get any clue regarding this.
Wim Vanni
Ranch Hand

Joined: Apr 06, 2011
Posts: 96

I have encountered the nosuchmethod error message in cases where there were double libraries in the classpath (e.g. LibraryX v1.1 and v1.5). It's worth checking this out, even more so because you can't seem to reproduce it on the server.

Cheers, Wim
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19697
    
  20

Naresh, I told you that in your other thread. Also, why are you using JSch and SFTP if you want to use SMB?
Naresh Kavala
Greenhorn

Joined: Jun 07, 2008
Posts: 23
Rob Spoor wrote:Naresh, I told you that in your other thread. Also, why are you using JSch and SFTP if you want to use SMB?


Hi Rob,

Thanks a lot for your concern. I have done like this using Jsch and SFTP.
1) Using Jsch, I get the latest file Name from the remote linux server.
2) Using sftp , trying to read data from the latest file.
I am almost there except reading the data. Connection is getting established.

Now I am trying to use SMB and I was successful in windows case but not able to establish connection for linux using SMB.

Coming to the duplication of methods, I am using only one version of Jsch and Appache- commons- vfs jars. I am not getting what other jars are contributing same method, but surely I will explore more on this
Naresh Kavala
Greenhorn

Joined: Jun 07, 2008
Posts: 23
Guys,

Finally I did it. I have removed commons- vfs -1.0 jar and able to read data with sftp using Jsch.

Once again thanks to Rob and Wim

Regards,
Naresh
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Connecting two linux machines using smb