Giter VIP home page Giter VIP logo

ezsmb's Introduction

EzSmb

SMB(Windows shared folder) Client Library powered by TalAloni's SmbLibrary, Xamarin & .NET Core Ready.

NuGet

Description

It's easy to use, and supports SMB ver2 for Windows 10.
Xamarin & .NET Core can access Windows Shared Folders and NAS without using mpr.dll or Netapi32.dll.
Supports .Net Standard 2.0.

Requirement

SMBLibrary.ForXamarin >= 1.4.6.1
NETStandard.Library >= 2.0.3

Usage

Add NuGet Package to your project.

PM> Install-Package EzSmb

and write code like this:

Get items in shared folder:

//using EzSmb;
//using System;

// Get folder Node.
var folder = await Node.GetNode(@"192.168.0.1\ShareName\FolderName", "userName", "password");

// List items
var nodes = await folder.GetList();
foreach (var node in nodes)
{
    Console.WriteLine($"Name: {node.Name}, Type: {node.Type}, LastAccessed: {node.LastAccessed:yyyy-MM-dd HH:mm:ss}");
}

Read file:

//using EzSmb;
//using System;
//using System.Text;
    
// Get file Node.
var file = await Node.GetNode(@"192.168.0.1\ShareName\FolderName\FileName.txt", "userName", "password");

// Get MemoryStream.
using (var stream = await file.Read())
{
    var text = Encoding.UTF8.GetString(stream.ToArray());
    Console.WriteLine(text);
}

and more:

Class Tree: Namespace.md

Breaking changes:

ver1.3.0: The first argument of Node.GetList method has been changed.

Node.GetList(string filter = "*", string relatedPath = null)
//           ^^ Inserted          ^^ move to second arg

Licence

LGPL v3 Licence

Author

Do-Be's

Contributors

upcu
synmra
icnocop
DenisKrasakovSDV

#What did I do wrong operation? synmra was not added to sidebar...

Links

GitHub - TalAloni/SMBLibrary: SMB client & server implements.
https://github.com/TalAloni/SMBLibrary

ezsmb's People

Contributors

deniskrasakovsdv avatar icnocop avatar ume05rw avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

ezsmb's Issues

Access denied trying to move file

[10:27:40 ERR] Errors: IP address removed: [EzSmb.Transports.Shares.Smb2Share.ExecMove] Create Handle Failed: path removed. NTStatus: STATUS_ACCESS_DENIED

Fixed by changing GENERIC_ALL to GENERIC_WRITE | DELETE in HandleType.ToArgs() (same as case HandleType.Delete), despite the comment in the code! I'm not sure if this fix is generic or specific to the setup at my company, and so I've not bothered with a PR.

case HandleType.Move:
// AccessMask.GENERIC_WRITE is failed in SMB2. Reqired GENERIC_ALL.
result.AccessMask
= AccessMask.GENERIC_WRITE
| AccessMask.DELETE
| AccessMask.SYNCHRONIZE;
result.ShareAccess = ShareAccess.Read;
result.CreateDisposition = CreateDisposition.FILE_OPEN;

Optionally use port 445 instead of port 137 to detect SMB servers

Hi.

I'm trying to get Node.GetServers() to return the SMB server listening on the loopback adapter but the NameQuery packet sent to port 137 doesn't seem to get a reply, and so it doesn't get added to the list.

Windows 10

Steps to reproduce:

  1. Disable "Server" service
  2. Install the "Microsoft KM-TEST Loopback Adapter"
  3. Bind adapter to IP 10.0.0.1 and Subnet Mask 255.255.255.0
  4. Create a text file in the folder "C:\Shared"
  5. Run SMBServer.exe
    IP Address: Any
    Transport: Direct TCP Transport (Port 445)
    Protocol: [X] SMB 1.0/CIFS [X] SMB 2.0/2.1
    [ ] Integrated Windows Authentication
  6. Click Start
  7. Modify EzSmb\Scanners\Scanner.cs by commenting out these two lines (47 and 62):
    || nic.NetworkInterfaceType == NetworkInterfaceType.Loopback
    || IPAddress.IsLoopback(uAddr.Address)
  8. Set a breakpoint after the call to Node.GetServers() in the test GetServersTest()
  9. Debug the test GetServersTest()
  10. Inspect the value of result1
  11. Notice 10.0.0.1 is not in the list

I discovered that instead of using port 137, I have to use port 445 to detect the SMB server.

Thank you.

Not able to move files

Hi.
First, thank you very much for this great library, it is very simple to use and it is a time saver.

Context

I'm trying to move files from UNC to UNC in a windows domain, running my application from a docker Linux container.

Testing environment

For testing this I have created the following file share on my local host

  • \\localhost\src
  • \\localhost\dst

Then I Added 2 .txt files in \\localhost\src

Succeeded

My container was able to read the .txt files from the src folder with the following code

        protected override async Task ExecuteAsync(CancellationToken stoppingToken)
        {
            var file = await Node.GetNode(@"<ipaddress>\src", "<username>", "<password>");
            var nodes = await file.GetList();
            foreach (var node in nodes)
            {
                Console.WriteLine(node.Name);
            }            
        }

Failed

Although, when trying to use the Move method, I don't get any exceptions but the files are not moved as expected

        protected override async Task ExecuteAsync(CancellationToken stoppingToken)
        {
            var folder = await Node.GetNode(@"<ipaddress>\src", "<username>", "<password>");
            var nodes = await folder.GetList();
            foreach (var node in nodes)
            {
                _logger.LogInformation($"Moving file {node.Name}");
                await node.Move($@"<ipaddress>\dst\{node.Name}");
            }            
        }

Am I doing something wrong? should this code expect to move files from src to dst file share?

No easy way to mock the connection for unit testing.

To implement some unit tests, I've written a wrapper around some of EzSmb. Instead of calling Node.GetNode, I created ISmbHelper and SmbHelper which have a non-static method GetNode. That way I can create a MockSmbHelper that just uses the local filesystem for unit test purposes. Ideally MockSmbHelper would create MockNode derived from Node but the internal constructor doesn't allow that.
Have you consider adding some mock classes to allow people to easily unit test? Would you be open to a patch adding that? If so any concerns about the approach I outlined here?

Any reason for the async API?

Hi,

Is there any reason for the the async API when it just tosses the job on the default scheduler?

I mean it doesn't saved any thread while it could based on the inherent IO latency.

Share Not Found: {ShareName} - Debug Help

Hello,
I am using EzSmb to connect to windows (server 2012 R2) file share from AWS Lambdas (.NET Core 6).
VPC on AWS side is configured properly, I have access to server.
The authorization is also working fine, because if I specify wrong credentials I get different error, or if I specify wrong address.

The issue appears to be that code cannot read anything from file share, but it appears that connection is successful.
When testing manually from other win servers it works fine.
I have similar setup in terms of file share, but on windows server 2019, and there is no issue with connection or reading/writing from lambda.

The exact error I am getting:
[EzSmb.Transports.Connection.GetNode] Share Not Found: Share

I tried all possible variations of GetNode method.
Specify domain, smbType, specify domain in username with @ or with \
But nothing is working.

Since I am not very familiar with SMB protocol, I seek an advise to what potential issue might be and how to further debug.

Thank you

Xamarin forms Node.GetNode always null

Hi,

When i execute var ipStrings = await Node.GetServers(); i can see my NAS Drive

When i running any of the following i always get null.

 // Normally.
                var server1 = await Node.GetNode("192.168.1.25", "testuser", "password1");

                // Connect by Anonymous User.
                var server2 = await Node.GetNode("192.168.1.25");

                // Connect with specified SMB version.
                var server3 = await Node.GetNode("192.168.1.25", new ParamSet()
                {
                    UserName = "testuser",
                    Password = "password1",
                    SmbType = SmbType.Smb1
                });

                // Connect by Windows-Domain Authentication. ** Not Supported SMB1 **
                var server4 = await Node.GetNode("192.168.0.1", new ParamSet()
                {
                    UserName = "testuser",
                    Password = "password1",
                    DomainName = "domainname.local"
                });

Running on a Google Pixel Pro 6 with the latest version of Xamarin Forms

No sure if this library actually works

If i run SharpCifs library (smb1 only) i can connect fine with the same details

Any ideas?

Not working in Windows Docker Container

I just tried to use the package inside a windows docker container (using the container with the tag mcr.microsoft.com/dotnet/runtime:5.0.7-windowsservercore-ltsc2019).

The package shows unexpected behaviour:
I am able to get a node using the following code snippet:
(Note that pathSource is the path to a folder on a network share)

using(var node = await Node.GetNode(pathSource, username, password))
{
...
}

The package behaves as expected and returns a non-null for the node object. The node type is correctly identified as "Folder".
When I try to get the files and folders inside of the node using the snippet

using(var node = await Node.GetNode(pathSource, username, password))
{
    var childs = await node.GetList();
}

I get an empty collection, even though there are files on the share.

Interestingly, the code works as expected on Windows 10 Pro.

An invalid IP address was specified.

Randomly you get An invalid IP address was specified. when using PCNAME local network but works 90% of the time. Any trick to this?

var homeFolder = await Node.GetNode("PCNAME1\Shared", null, true);

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.