ume05rw / SharpCifs.Std

SharpCifs.Std is a port from SharpCifs to .NET Standard. Original SharpCifs: https://github.com/zinkpad/SharpCifs
GNU Lesser General Public License v2.1
86 stars 34 forks source link

Smb Connection fail #24

Open LostJ3ster opened 6 years ago

LostJ3ster commented 6 years ago

Hi, if I'm opening my App I'd like to connect to smb server (Works). I also want to change the user/password that access to the smb server. And thats where I get to my problem. Even if the user/password is incorrect, I still can upload files. If I watch the file information on smb, those files were created with the previous, successfully logged in user.

My question: How am I able to disconnect and completely log off with the user credentials?

I already tried the following: SmbFile.Initialize(); SmbSession.ClearCachedConnection(); SmbTransport.ClearCachedConnections(); SmbTransport.ClearCachedConnections(true);

I'm trying the procedure doing the following:

I've got a method for testing, if the connection is successfull. The method is giving me a boolean.

try
                {
                    SharpCifs.Config.SetProperty("jcifs.smb.client.username", user);
                    SharpCifs.Config.SetProperty("jcifs.smb.client.password", password);
                    SharpCifs.Config.SetProperty("jcifs.smb.client.responseTimeout", "2000");

                    var smb1 = new SmbFile("smb://" + path);

                    if (smb1.Exists())
                    {
                        var test = new SmbFile("smb://" + path+"ConnectionTest"+new Random().Next(0, 1000)+".txt");
                        test.CreateNewFile();

                        var writeStream = test.GetOutputStream();

                        writeStream.Write(Encoding.UTF8.GetBytes("Connection successfull"));
                        writeStream.Dispose();

                        return true;
                    }
                    return false;
                }
                catch (Exception e)
                {
                    Debug.WriteLine(e.StackTrace);
                    return false;
                }

I also write the variable content in debug, to see whats the variables value. The same thing I do for the SharpCifs Config Properties. Those values looks how they supposed to look.

Hope you can help me quickly.

Have a nice day.

LostJ3ster commented 6 years ago

Didn't solved it using the SharpCifs config. My Workaround was to use the direct connection via var test = new SmbFile("smb://UserName:Password@PathToFile");

But nevertheless, is there a option for cleaning the SharpCifs Config and maybe the sessions or previous connections?