• 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

Connecting two linux machines using smb

 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 96
Eclipse IDE Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
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
Check out JCIFS; it makes it a lot easier to work with SMB shares.
 
Naresh Kavala
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 96
Eclipse IDE Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
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
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
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
I found a beautiful pie. And a tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic