hierynomus / smbj

Server Message Block (SMB2, SMB3) implementation in Java
Other
707 stars 180 forks source link

Examples #35

Open visch opened 7 years ago

visch commented 7 years ago

The readme mentions some examples (Maybe copied from sshj), but I don't think there's any available?

Examples would be awesome :D

hierynomus commented 7 years ago

Hi @visch, You're right, part of the README was copied from SSHJ ;). The goal is indeed to have some usage examples, Feel free to send a PR with examples if you happen to have some time.

gidravlic commented 7 years ago

Yes, it would be nice to add examples of the use the library

HubKing commented 7 years ago

How to use it? I cannot find documentation (other than the class references) or any example in this site or by searching Google. I am not even looking for detailed examples; I am just looking for a basic example like reading a file from a Windows shared directory, and I cannot find it.

hierynomus commented 7 years ago

@HubKing have you looked at the SmbjTest testcases? They should provide some starting point at least.

NinjaChris16 commented 7 years ago

@hierynomus I am currently working on some usage examples in Groovy and I was wondering if you preferred them in Java over Groovy or what your preference was in general?

mtamassia commented 7 years ago

@NinjaChris16 I sent a small PR for the examples currently on the README and they are in Java. I guess you could also have Groovy examples but @hierynomus has to decide if he wants them...

hierynomus commented 7 years ago

Either Java or Groovy works. I'm still thinking about what would be the best approach. I've rewritten one of the integration tests to be more clear. Maybe if we add more integration tests usage is clearer. Those would be in Groovy.

Or like in sshj we add a directory with copy-paste examples. I would prefer those to be in Java.

Sent from my Samsung SM-G950F using FastHub

sadie-sorenson commented 6 years ago

are there any examples of using the SmbFiles.copy(File source, DiskShare share, String destPath, boolean overwrite) method?

andreasql commented 6 years ago

hi All, here again to annoy all of you, seeking for documentation :)... after having performed a copy from android to a windows share, I'm trying to understand how to do the reverse... copy from windows share to android \Dowload folder... is it just a matter of providing the AndroidPath + fileName as the destPath parameter of the SmbFiles.copy method, like

String androidDirectory = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS)).getPath();
String inFileName = "fileName.txt" 

File fileIn = new File(androidDirectory, inFileName);
int writtenB = SmbFiles.copy(fileIn, share, **androidDirectory + "/" + inFileName**, true);

?

and what about reading a share inputstream? for instance, jcifs provided a SmbFileInputStream to read similarly to

StringBuilder outBuilder = new StringBuilder();
BufferedReader reader = null;
String lineReader = null;
try {
   SmbFile smbFile = new SmbFile(fileName, auth);
   if (smbFile.exists()) {
      reader = new BufferedReader(new InputStreamReader(new **SmbFileInputStream(smbFile)**));

      while ((lineReader = reader.readLine()) != null) {
         if (outBuilder.length() > 0) {
            outBuilder.append("\n");
         }
         outBuilder.append(lineReader);
      }
   }
} catch (Exception ex) {
   m_Params.Exception = ex.getMessage();
} finally {
   try {
      if ( reader != null) { reader.close(); }
      reader = null;
   } catch (Exception ex) {
      m_Params.Exception = ex.getMessage();
   }
}

does the project provide similar features? TIA Andrea

viorelAlexandrescu commented 5 years ago

Hello,

I've just started to use this lib and I found it very hard to make things work. Is this issue still open? Are there more examples than in the README ?

Thanks

ghost commented 5 years ago

@viorelAlexandrescu There are some Tests/Specifications in the repository that helped me a lot to implement it in our application.

viorelAlexandrescu commented 5 years ago

@TheRealHypo could you please provide a path towards those resources? thank you!